Skip to content

Instantly share code, notes, and snippets.

@armentpau
Last active September 8, 2017 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armentpau/41290faae2451f9fb6a9bbb179c97b79 to your computer and use it in GitHub Desktop.
Save armentpau/41290faae2451f9fb6a9bbb179c97b79 to your computer and use it in GitHub Desktop.
Test connectivity and convert ip to computer name
#TODO: Place custom script here
Import-Module Activedirectory
$preSearchComputer = "10.140.8.155"
foreach ($item in ([system.Net.dns]::GetHostByName($preSearchComputer)).AddressList.ipaddresstostring)
{
if (Test-Connection -ComputerName $item -Count 1 -Quiet)
{
$Computer = ([System.Net.Dns]::GetHostByAddress($item)).HostName
$system = Get-WmiObject Win32_ComputerSystem -ComputerName "$Computer" | Select-Object -property name
$networkResult = Get-WmiObject win32_networkadapterconfiguration -Filter 'ipenabled = "true"' -ComputerName $Computer
$os = Get-WmiObject Win32_OperatingSystem -ComputerName $Computer
$description = Get-ADComputer -Filter ('Name -like "*' + $($Computer.Split("."))[0] + '*"') -Property description
$Object = New-Object PSObject -Property @{
'Name' = $system.Name
'IP Address' = $networkResult.IPAddress
'OS Caption' = $os.Caption
'Description' = $description.description
}
$richtextbox1.Text = $object.psobject.properties | Where-Object{ $_.membertype -eq "noteproperty" } | ForEach-Object{
"$($_.name) - $($_.value)`r`n"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment