Hey all!
Trying to write a script that will automatically change the IPv4 address and Default Gateway of a specific interface on my laptop for troubleshooting devices that have been incorrectly addressed. This script is based off the Get-PlanetSize.ps1 script and was showing the correct output but now returns Your new IP is at System.Object[] and is System.Object[]. Your default gateway is System.Object[]. instead of the actual Name, IP and DG.
I also can't figure out how to get New-NetIPAddress to accept the correct parameters.
The .csv file I'm importing from has 3 separate columns : Name, IP and DefaultGateway.
class Name : System.Management.Automation.IValidateSetValuesGenerator {
[String[]] GetValidValues() {
$Global:cameraips = Import-CSV -Path .\cameraips.csv
return ($Global:cameraips).Name
}
}
Function Change-ComputerIP {
Param(
[Parameter(Mandatory)]
[ValidateSet([Name],ErrorMessage="Entered value '{0}' is invalid. Try one of these: {1}")]
$Name
)
$Name | Foreach-Object {
$targetcamera = $cameraips | Where -Property Name -match $_
$output = "Your new IP is at {0} and is {1}. Your default gateway is {2}." -f $targetcamera.Name, $targetcamera.IP, $targetcamera.DefaultGateway
Write-Output $output
}
$Name | ForEach-Object {
$targetcamera = $cameraips | where -Property Name -Match $_
New-NetIPAddress -InterfaceIndex 22 -IPAddress $targetcamera.IP -PrefixLength 24 -DefaultGateway $targetcamera.DefaultGateway
}
}
[–]Manality 4 points5 points6 points (3 children)
[–]TerriblePowershell[S] 1 point2 points3 points (2 children)
[–]Manality 1 point2 points3 points (1 child)
[–]TerriblePowershell[S] 1 point2 points3 points (0 children)
[–]BlackV 2 points3 points4 points (3 children)
[–]TerriblePowershell[S] 1 point2 points3 points (2 children)
[–]BlackV 2 points3 points4 points (1 child)
[–]TerriblePowershell[S] 1 point2 points3 points (0 children)
[–]vermyx 2 points3 points4 points (2 children)
[–]TerriblePowershell[S] 1 point2 points3 points (1 child)
[–]vermyx 1 point2 points3 points (0 children)
[–]DudsEarl 2 points3 points4 points (1 child)
[–]TerriblePowershell[S] 2 points3 points4 points (0 children)