Posted in
Windows Powershell,
Windows Server |
2 Comments | 2,253 views | 21/06/2013 09:49
You can check ip addresses of server names like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| $Servers = Get-Content C:\Servers.txt
foreach ($Server in $Servers)
{
$IPAddress = [System.Net.Dns]::GetHostAddresses("$Server").IPAddressToString
If ($IPAddress -like "172.29*")
{
Write-Host "Test Server"
Add-Content -Path C:\testservers.txt -Value $Server
}
else
{
Write-Host "Prod Server"
Add-Content -Path C:\prodservers.txt -Value $Server
}
} |
$Servers = Get-Content C:\Servers.txt
foreach ($Server in $Servers)
{
$IPAddress = [System.Net.Dns]::GetHostAddresses("$Server").IPAddressToString
If ($IPAddress -like "172.29*")
{
Write-Host "Test Server"
Add-Content -Path C:\testservers.txt -Value $Server
}
else
{
Write-Host "Prod Server"
Add-Content -Path C:\prodservers.txt -Value $Server
}
}
As you see, i split them into 2 different groups.