13 Replies Latest reply on Jan 3, 2017 9:23 AM by tylerwinfield

    IPAM + PowerShell




      Used the following to get an available IP:How to use the IPAM API and get "Free IP Address"


      Getting an error while trying to update any information:

      Set-SwisObject : Operation not supported on IPAM.IPNode


      While using the following:


      $ip = Get-SwisData $swis 'SELECT TOP 1 I.DisplayName FROM IPAM.IPNode I WHERE Status=2 AND I.Subnet.DisplayName = '''''

      $ipobject = Get-SwisObject -Uri (Get-SwisData $swis ('SELECT Uri from IPAM.IPNode where IPAddress = ''' + $ip + '''')) -SwisConnection $swis


      $customProps = @{




      Set-SwisObject -Uri $ipobject.Uri -SwisConnection $swis -Properties $customProps


      Anyone trying to reserve IPs???

        • Re: IPAM + PowerShell

          The IPAM product doesn't support Update or create operations.


          We're going to be looking at alternatives in the next year because the lack of a full API for IPAM has become a show-stopper.

          • Re: IPAM + PowerShell

            Registered on the site just so I could post...


            Straight up asinine that IPAM doesn't yet have full-featured built-in automation capabilities. I'll recommend strongly against this product.

            • Re: IPAM + PowerShell

              FWIW, this is currently achievable by emulating a browser session that uses the "edit IP address" page. I'm using two separate PowerShell scripts to get and set the IP reservation information (both run via VMware Orchestrator). I consider it somewhat of a hack simply because the "set" operations MUST run in a local session. This means the script has to be stored as a .ps1 file on the system that will be running it while the 'get' can be done through a remote session. In my use case, the orchestrator application hides this subtle difference from those using the workflows so its not a big issue. I would prefer proper IPAM APIs of course though.  That said, here's the scripts I use.


              The 'get' operation is pretty standard and requires the PowerOrion module be installed, but its important that the "SubnetId" and "Ordinal" (or whatever you keys you choose to store them as) are retained for the 'set' operation. I added more data to the PowerOrion module query for the next available IP address from a subnet. The modified SELECT statement for Get-OrionNextAvailableIPAddress returns the following data values: SELECT TOP 1 I.IpNodeId , I.Uri , I.DisplayName , I.SubnetId , I.IPOrdinal , I.IPAddress , I.Subnet.Address , I.Subnet.AddressMask , I.Subnet.DisplayName as Subnet FROM IPAM.IPNode I. In my specific case, writing the data to the host output made it easy to collect and parse with VMware Orchestrator.


              Import-Module PowerOrion
              $SwisConnection = Connect-Swis -UserName "$IPAMUsername" -Password "$IPAMPassword" -Hostname $IPAMHostname
              $IPAddress = Get-OrionNextAvailableIPAddress -swisconnection $SwisConnection -Subnet "$Subnet"
              Write-Host "IPAddress=$($IPAddress.IPAddress)"
              Write-Host "SubnetMask=$($IPAddress.AddressMask)"
              Write-Host "Gateway=$($IPAddress.Address)"
              Write-Host "Uri=$($IPAddress.Uri)"
              Write-Host "SubnetId=$($IPAddress.SubnetId)"
              Write-Host "Ordinal=$($IPAddress.IPOrdinal)"

              The 'set' operation MUST be stored as a .ps1 file on the system intended to run the script. The 'SubnetId' and 'SubnetOrdinal' are required to identify the address being reserved.


              $postParams = @{__EVENTTARGET='ctl00$BodyContent$ctl05';__EVENTARGUMENT='';'ctl00$BodyContent$Username'="$IPAMUsername";'ctl00$BodyContent$Password'="$IPAMPassword"}
              Invoke-WebRequest -Uri "http://$IPAMHostname/Orion/Login.aspx?autologin=no" -Method POST -SessionVariable LocalSession -Body $postParams -MaximumRedirection 3

              $EditPage = Invoke-WebRequest -Uri "http://$IPAMHostname/Orion/IPAM/ip.edit.aspx?SubnetId=$SubnetId&ipOrdinal=$SubnetOrdinal" -UseBasicParsing -Method GET -WebSession $LocalSession -MaximumRedirection 3
              $ViewState = $($EditPage.InputFields | Where-Object { $_.id -eq "__VIEWSTATE" } | Select Value).Value
              $ViewStateGenerator = $($EditPage.InputFields | Where-Object { $_.id -eq "__VIEWSTATEGENERATOR" } | Select Value).Value

              $postParams = @{__VIEWSTATE=$ViewState;__VIEWSTATEGENERATOR=$ViewStateGenerator;__EVENTTARGET='ctl00$ctl00$ctl00$BodyContent$ContentPlaceHolder1$main$MsgListener';__EVENTARGUMENT='Save';'ctl00$ctl00$ctl00$BodyContent$ContentPlaceHolder1$main$ddlStatus'="$Status";'ctl00$ctl00$ctl00$BodyContent$ContentPlaceHolder1$main$txtAlias'="$Alias"}
              Invoke-WebRequest -Uri "http://$IPAMHostname/Orion/IPAM/ip.edit.aspx?SubnetId=$SubnetId&ipOrdinal=$SubnetOrdinal" -UseBasicParsing -Method POST -WebSession $LocalSession -Body $postParams -MaximumRedirection 3


              Our networking team requested we add the hostname of the server reserving the IP in the "alias" field. The same should work for other fields in the ip.edit.aspx form by adding the field ID and value to the $postParams before the final web request.

              1 of 1 people found this helpful