So I have a master script that works. I wanted to pull a small section to create a stand alone script. It works…the first time. Then if I repeat the process it seems to pull the information from the previous run. My scripting is still fairly bad so cant get my head around where the issue is.
Incidentally, there are normally about 80 2nd octets and 10 3rd octets but I stripped them out just to not be posting internal data
cls $IP = Read-Host -Prompt "What is the IP Address of the computer?" #split IP address and query second and third octets against following table to output Network and VLAN ForEach-Object { $IP = ($IP).Split('.')switch ($IP[1]) { 168 { $Location = "ADSL Unmanaged Network " } default { $Location = "Other" } }switch ($IP[2]) { 216 { $User = "Lab Test PC" } default { $User = "Other" } } "-----------------------------------------------------------------------------------------------------------------------------------" Write-host -ForegroundColor Green "`n" "> Network Information" "`n" $obj = New-Object –typename PSObject $obj | Add-Member –membertype NoteProperty –name 'IPAddress' –value ("$($IP)") –PassThru | Add-Member –membertype NoteProperty –name 'Network' –value ("$Location") –PassThru | Add-Member –membertype NoteProperty –name 'VLAN' –value ("$User") #$All += $obj }$All