This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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