Sunday, June 23, 2019

Ping.ps1




1. Information & Troubleshooting\1. Command Line\Automation via Batch Files - PowerShell\Dell EMC\PS Script - All in One\Ping\Only Ping & to Get IPAddress\ping.ps1



$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$servers = Get-Content "$scriptPath\Servers.txt"

#$UserName = Read-Host "Enter User Name:"
#$Password = Read-Host -AsSecureString "Enter Your Password:"
#$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, $Password


$infoColl = @()
foreach ($S in $Servers)

{

       $CPUInfo = if (test-Connection -ComputerName $S -Count 1 -Quiet ) {"Pinging "} else {"Not pinging"} 
       $IPs = if (Test-Connection $S -count 1 -Quiet) {Test-Connection $S -count 1}
     


Foreach ($CPU in $CPUInfo)
{
$infoObject = New-Object PSObject
#The following add data to the infoObjects.
Add-Member -inputObject $infoObject -memberType NoteProperty -name "ServerName" -value $S
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Ping Status" -value $CPUInfo
Add-Member -inputObject $infoObject -memberType NoteProperty -name "IP Address" -value $IPs.IPV4Address



        $infoObject #Output to the screen for a visual feedback.
$infoColl += $infoObject
}
}
$infoColl | Export-Csv -path "$scriptPath\Server_Inventory_$((Get-Date).ToString('MM-dd-yyyy')).csv" -NoTypeInformation #Export the results in csv file.

No comments:

Post a Comment