PowerShell | Connection Tests
#=================Simple way to Collect list of WINRM accessible systems ================
​
$ListofComputers = Get-Content C:\temp\Servers.txt
​
$ComputersAccess=Invoke-Command -ComputerName $ListofComputers -ErrorAction SilentlyContinue -ScriptBlock {$env:COMPUTERNAME}
​
$ComputersAccess
#=================PowerShell Loop and PING test tab delimited output to file================
$COMPS=Get-Content C:\temp\MyList.txt
​
foreach ($COMP in $COMPS){
Try{
$IP=test-connection $COMP -Count 1 -ErrorAction Stop | select -ExpandProperty IPv4address
$COMP + "`t" + $IP |Tee-Object C:\Temp\Computer_Checker.txt -Append
}Catch{
$COMP + "`tNotFound" | Tee-Object C:\Temp\Computer_Checker.txt -Append
}
}
# ================PowerShell Test Path to Website===================
$URL="Http://www.Google.com"
$StatusCode=Invoke-webrequest $URL -DisableKeepAlive -UseBasicParsing -Method head -TimeoutSec 3 | Select -ExpandProperty StatusCode
if ($StatusCode -eq 200){
write-Host "Website is Online"
}Else{
Write-Host "The Website is Down"
}
​
​
# ================PowerShell Test Path to A Folder=================
Test-Path C:\temp
​
​
# ================PowerShell Test Path in Registry ================
Test-Path HKLM:\HARDWARE\DESCRIPTION\System
​
​
​
#====== PowerShell Test Path to Network Share===============
Test-Path \\POWERSHELL-PC\Temp
​
If(Test-Path \\POWERSHELL-PC\Temp){
Write-Output "Path Exists"
}Else{
Write-Output "No Path Found"
}
​
​
​
# Sets the location and port to scan and reports back detailed network information.
Test-NetConnection imap.gmail.com -Port 993 -InformationLevel "Detailed"
Test-NetConnection smtp.gmail.com -Port 465 -InformationLevel "Detailed"