Here is a script I have that is finding the name and password of a wifi network when shows it on the screen:
$CmdL = @("Command1", "Command2", "WIFI NAME")
Trap [System.Management.Automation.RuntimeException] {
Write-Color "No such WiFi exists" -Color "Red"
Continue
}
$S = $Null
$E = Get-AllWifiPasswords
Write-Host
$S = ($E | sls ($CmdL[2])).ToString().Trim()
Write-Color $S -Color "Green"
Write-Host
However, if it can't find the name of the network then it adds a trailing newline to the end:
(newline)
No such WiFi exists
(newline)
(newline)
I have no idea why that newline is there, as it should not be. How can I remove it so that the error output is as follows:
(newline)
No such WiFi exists
(newline)