Skip to content

Instantly share code, notes, and snippets.

Created January 18, 2016 08:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/365d40da620cf9b94b6d to your computer and use it in GitHub Desktop.
$CommandLineFilePath = 'C:\Temp\Server.txt'
Function Get-PSPSubnetMask {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[System.String]
$FilePath
)
Write-Verbose "Retrieving server names from text file..."
#Retrieve a list of PSP servers from text file and set to $serverNames
$ServerNames = Get-Content $FilePath
Write-Verbose "Gathering network information..."
#Iterate through each of the server names
Foreach ($ServerName in $ServerNames) {
#Check if the server is online before doing the remote command
If (Test-Connection -ComputerName $ServerName -Quiet -Count 1) {
$EthernetAdapters = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'True' and Description like 'Intel(R) Ethernet%'" -ComputerName $ServerName
Foreach ($EthernetAdapter in $EthernetAdapters) {
$SubnetMask = $EthernetAdapter.IPSubnet[0]
If ($SubnetMask -eq "255.255.255.0") {
New-Object -TypeName PSCustomObject -Property @{
Server = $ServerName
SubnetMask = $SubnetMask } |
Export-Csv C:\Temp\PSPSubnetMask.csv -Append }#If $Subnetmask
Else {
Write-Verbose "$ServerName already has a /23 configuration"
} #Else
} #Foreach ($EthernetAdapter in $EthernetAdapters) {
} #If (Test-Connection -ComputerName $ServerName -Quiet) {
} #Foreach ($ServerName in $ServerNames) {
Write-Verbose "Script completed successfully"
} #Function Get-PSPSubnetMask
#Run the Get-PSPSubnetMask function using the text file path that was passed to this script
Get-PSPSubnetMask -FilePath $CommandLineFilePath -Verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment