Count of rows in Text File
$totalrows = Import-Csv C:\urls.csv | Measure-Object | Select-Object -expand count
Open/Read text File
AccountNames.csv
AccountName
Domain\Name1
Domain\Name2
$AcctFile="C:\AccountNames.csv"
ipcsv $AcctFile | foreach {
$AName =$_.AccountName
}
Write-host
Write-host "Feature: " $AName -foregroundcolor yellow
Clear-Host
TimeStamp
$strTimestamp = [string](Get-Date -format "yyyy-MM-dd_hh-mm-ss")
$strLogFile = ($strFilePath + "FileName_" + $strTimestamp + ".log")
Log to File
$AName +",Blog-NotFound" | Out-File ($strLogFile) -append
Write-Output "$Class deleted on $CommunityList" | Out-File -Append $strLogFile
"Count :"+$UrlsCount | Out-File -Append $DeletedReport
Log File Creation Prompt:
if ((Test-Path -path $FilePath) -ne $True) {
$NewPathPrompt = "$FilePath does not exist! Would you like to create it?"
$NewPathMessage = ""
$NewPathYes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
"Creates new directory at $FilePath"
$NewPathNo = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
"Do not create new directory and exit"
$NewPathOptions = [System.Management.Automation.Host.ChoiceDescription[]]($NewPathYes, $NewPathNo)
$NewPathResult = $host.ui.PromptForChoice($NewPathPrompt, $NewPathMessage, $NewPathOptions, 0)
switch ($NewPathResult)
{
0 {New-Item $FilePath -type directory}
1 {Write-Host "Cannot continue without valid directory to save output file, exiting..."
Exit
}
}
}