$hostname = 'powershellmagazine.com' # run the console-based application ASYNCHRONOUSLY in its own # window (PowerShell continues) and return the # process object (-PassThru) # Hide the new window (you can also show it if you want) $process = Start-Process-FilePath ping -ArgumentList"$hostname -n 4 -w 2000"-WindowStyleHidden-PassThru
# wait for the process to complete, and meanwhile # display some dots to indicate progress: do { Write-Host'.'-NoNewline Start-Sleep-Milliseconds300 } until ($process.HasExited) Write-Host
# the Error Level information is then found in ExitCode: $IsOnline = $process.ExitCode -eq0 $IsOnline
$hostname = 'powershellmagazine.com' # run the console-based application synchronously in the PowerShell window, # and return the process object (-PassThru) $process = Start-Process-FilePath ping -ArgumentList"$hostname -n 2 -w 2000"-Wait-NoNewWindow-PassThru
# the Error Level information is then found in ExitCode: $IsOnline = $process.ExitCode -eq0 $IsOnline
$hostname = 'powershellmagazine.com' # run console-based executable directly # and disregard text results $null = ping.exe $hostname-n2-w2000 # instead look at the exit code delivered in # $LASTEXITCODE. Ping.exe returns 0 if a # response was received: $IsOnline = $LASTEXITCODE-eq0 $IsOnline
functionGet-CsvDelimiter($Path) { # get the header line $headerLine = Get-Content$Path | Select-Object-First1
# examine header line per character $headerline.ToCharArray() | # find all non-alphanumeric characters Where-Object { $_-notlike'[a-z0-9äöüß"()]' } | # find the one that occurs most often Group-Object-NoElement | Sort-Object-Descending-Property Count | # return it Select-Object-First1-ExpandProperty Name }
functionImport-CsvWithDuplicate($Path, $Delimiter=',', $Encoding='UTF8') { # get the header line and all header items $headerLine = Get-Content$Path | Select-Object-First1 $headers = $headerLine.Split($Delimiter)
# check for duplicate header names, and if found, add an incremented # number to it $dupDict = @{} $newHeaders = @(foreach($headerin$headers) { $incrementor = 1 $header = $header.Trim('"') $newheader = $header
# increment numbers until the new name is unique while ($dupDict.ContainsKey($newheader) -eq$true) { $newheader = "$header$incrementor" $incrementor++ }
$dupDict.Add($newheader, $header)
# return the new header, producing a string array $newheader })
# read the CSV without its own headers.. Get-Content-Path$Path-Encoding$Encoding | Select-Object-Skip1 | # ..and replace headers with newly created list ConvertFrom-CSV-Delimiter$Delimiter-Header$newHeaders }