Hello,
I am trying to create a powershell script that will create an IP reservation and set a custom property on the IP address. The reservation portion is working. However the custom property is failing with the following error: Set-SwisObject : The given key was not present in the dictionary.
I am aware I need to create the field first and I have placed what I think is correct in the script.
Any help would be appreciated. My script is below:
Add-PSSnapin SwisSnapin -ErrorAction SilentlyContinue
$swis = Connect-Swis -Hostname 10.107.11.81 -Trusted
$ipaddr = Import-Csv -Path "\\sharent1\nshare\group#4\Powershell\IP-Reservations-SW-DHCPserver\new-ip-addresses.csv"
foreach ($si in $ipaddr){
$mac=$($si.mac)
$ip=$($si.ip)
$name=$($si.dhcpclientname)
$custom=$($si.SFH_Description)
$status=$($si.Status)
Invoke-SwisVerb $swis IPAM.DhcpDnsManagement CreateIpReservation @($ip,"10.113.9.1",$name,$mac,"DhcpOnly")
$IPtoIdQuery = "SELECT IpNodeId FROM IPAM.IPNode where IPAddress like '"+ $ip+"'"
$IPAMNode = Get-SwisData -SwisConnection $swis -Query $IPtoIdQuery
Write-host $IPAMNode
New-SwisObject $swis -EntityType 'IPAM.IPNodeAttr' -Properties @{ IPNodeId = $IPAMNode; }
$CustomURI = 'swis://10.107.11.81/Orion/IPAM.IPNode/IpNodeId='+$IPAMNode+'/Custom'
Set-SwisObject $swis -Uri $CustomURI -Properties @{ SFH_Description = $custom }
Invoke-SwisVerb $swis IPAM.SubnetManagement ChangeIPStatus @($ip, $status)
}