
If you're tasked with pinging a huge list of workstations, look no further. Gone are the days where we must keyboard cram in the command prompt to test connectivity.First off, let's get you started with PowerShell. PowerShell is a free program offered by Microsoft and it's basically a command prompt on steroids.It's easy to find and easy to download. Get your hands on Version 3 at least - optimally PowerShell ISE v4.The program is pretty self-explanatory. You can use all the same commands you use in the command prompt, as well as a whole plethora of new commands. PowerShell doesn't just stop there. You can add new functions that are useful with your everyday applications. For instance, I was able to add functions in PowerShell that helped me manage SCCM.All you have to do is look it up online.So once you've downloaded it, you're going to want to...file -> new -> paste code (below)Â -> save as (make sure you save as .ps1 file)
Function Popup-Box($Message,$Title,$Button,$Icon){Add-Type -AssemblyName Microsoft.VisualBasicReturn [Microsoft.VisualBasic.Interaction]::MsgBox("$Message","$Button,MsgBoxSetForeground,$Icon","$Title")}Function Open-File($Directory,$Filter,$Title){Add-Type -AssemblyName System.Windows.Forms#Commonly used file types that i allow to be abriviated when passing it to the functionIf ($Filter.ToLower() -eq "all"){$Filter = "All Files(*.*)|*.*"}If ($Filter.ToLower() -eq "txt"){$Filter = "Text Files(*.txt)|*.txt"}If ($Filter.ToLower() -EQ "csv"){$Filter = "Comma Separated Value(*.csv)|*.csv"}If ($Filter.ToLower() -EQ "txtcsv"){$Filter = "Text Files(*.txt)|*.txt|Comma Separated Value(*.csv)|*.csv"}$Title = "$Title -DO NOT PRESS HELP OR THE SCRIPT WILL BECOME UNRESPONSIVE"$SelectAFile = New-Object System.Windows.Forms.OpenFileDialog$SelectAFile.InitialDirectory = $Directory$SelectAFile.Filter = $Filter$SelectAFile.Title = $Title$SelectAFile.ShowHelp = $True$SelectAFileChoice = $SelectAFile.ShowDialog()Switch($SelectAFileChoice){"Ok"{Return $SelectAFile.FileName}"Cancel"{$CancelCheck = Popup-Box -Message "Are You Sure You Want To Cancel?" -Title "You Pressed Cancel!" -Button "YesNo" -Icon "Information"Switch($CancelCheck){"yes"{Exit}"no"{Open-File -Directory $Directory -Filter $Filter -Title $Title.Replace("-DO NOT PRESS HELP OR THE SCRIPT WILL BECOME UNRESPONSIVE", "")}}}}}Function Save-File($SaveFileTitle,$SaveFileFilter,$SaveFileInitialDirectory,$SaveFileName){If ($SaveFileFilter -eq "all"){$SaveFileFilter = "All Files(*.*)|*.*"}If ($SaveFileFilter -eq "txt"){$SaveFileFilter = "Text Files(*.txt)|*.txt"}If ($SaveFileFilter -EQ "csv"){$SaveFileFilter = "Comma Separated Value(*.csv)|*.csv"}If ($SaveFileFilter -EQ "txtcsv"){$SaveFileFilter = "Text Files(*.txt)|*.txt|Comma Separated Value(*.csv)|*.csv"}$SaveFileTitle = "$SaveFileTitle -DO NOT PRESS HELP OR THE SCRIPT WILL BECOME UNRESPONSIVE"$SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog$SaveFileDialog.CheckPathExists = $True$SaveFileDialog.RestoreDirectory = $True$SaveFileDialog.ShowHelp = $True$SaveFileDialog.ValidateNames = $True$SaveFileDialog.OverwritePrompt = $True$SaveFileDialog.Title = $SaveFileTitle$SaveFileDialog.Filter = $SaveFileFilter$SaveFileDialog.InitialDirectory = $SaveFileInitialDirectory$SaveFileDialog.FileName = $SaveFileName$SaveFileDialogChoice = $SaveFileDialog.ShowDialog()Switch($SaveFileDialogChoice){"Ok"{Return $SaveFileDialog.Filename}"Cancel"{$CancelCheck = Popup-Box -Message "Are You Sure You Want To Cancel?" -Title "You Pressed Cancel!" -Button "YesNo" -Icon "Information"Switch($CancelCheck){"yes"{Exit}"no"{Save-File -SaveFileInitialDirectory $SaveFileInitialDirectory -SaveFileFilter $SaveFileFilter -SaveFileTitle $SaveFileTitle.Replace("-DO NOT PRESS HELP OR THE SCRIPT WILL BECOME UNRESPONSIVE", "")}}}}}Remove-Job *$JobList = @()$SuccessfulPings = @()$UnsuccessfulPings = @()$ServerListPath = Open-File -Directory "C:" -Filter "TXT" -Title "Please Select The Server List File"$Servers = Get-Content $ServerListPathForEach ($Server In $Servers){$JobList += Start-Job -Scriptblock {If (Test-Connection $Args[0] -Count 1 -Quiet){$SuccessfulPings = "$($Args[0]) Yes"Return $SuccessfulPings}Else{$UnsuccessfulPings = "$($Args[0]) No"Return $UnsuccessfulPings}} -Argumentlist $Server}$JobTracker = "Not Finished"Do {$JobList | ForEach {If ($_.State -EQ "Completed"){If ($(Receive-Job $_ -Keep) -Match "Yes"){$SuccessfulPings += $(Receive-Job $_).Trimend(" Yes")Remove-Job $_}ElseIf ($(Receive-Job $_ -Keep) -Match "No"){$UnsuccessfulPings += $(Receive-Job $_).Trimend(" No")Remove-Job $_}}}$JobTracker = $(Job)}Until ($JobTracker -EQ $Null)If ($UnsuccessfulPings){$UnsuccessfulPath = Save-File SaveFileTitle "Failed Ping Export File" -SaveFileFilter "TXT" -SaveFileInitialDirectory "C:" -SaveFileName "Failed Ping Export"If ($UnsuccessfulPath){Set-Content -Path $UnsuccessfulPath -Value $UnsuccessfulPings}}If ($SuccessfulPings){$SuccessfulPath = Save-File SaveFileTitle "Successful Ping Export File" -SaveFileFilter "TXT" -SaveFileInitialDirectory "C:" -SaveFileName "Successful Ping Export"If ($SuccessfulPath){Set-Content $SuccessfulPath -Value $SuccessfulPings}}
You made it! Don't copy this text, only the bracket above this.Once you've done that, make a text file in the same location, put one workstation name or IP per line in the document...
Nothing Else. Like this:workstationdfiushdfoh1293087workstationfdksfjsdlfk2938029... or ...192.168.1.1192.168.1.2 That's it!Right-click the PowerShell script you made and "Run With PowerShell" and then select the .txt file with the workstations names/IPs in it. Let it do it's thing (it'll take a bit if there are a bunch of workstations/IPs in your list). Eventually, it will prompt you to let it output "Failed Ping List" and "Successful Ping List" - just hit save on both of those. Open those files and it'll show you which ones are connected to the network and which ones aren't!GLHF- Sheridan