I'm a newbie at powershell/programming in general and currently attempting to update admin passwords on Chatsworth CPI PDUs. The PDUs are daisy-chained together and accessed through the primary/alternate PDU IPs. Each PDU has a unique identifier that is passed as a header. After validation the API returns a Sessionid that must also be passed with the identifier to other endpoints. The Sessionid is only valid for 10 minutes
I'm looking for a way to loop both the identifiers and Sessionid with the Invoke-RestMethod to update all of the passwords.
What would be the best method to accomplish this?
This is what I am currently running to test retrieving the sessionids
#Unique Identifier for each PDU
$Identifier = @("80224", "80245", "80181", "76998", "80226", "80949", "80479", "80556", "86619", "86621", "80521", "80925", "80293", "80924", "76893", "80514", "80363", "81280", "80476")
#Loop each identifier to endpoint
$Sessionid = foreach ($identity in $Identifier) {
<# $$header is the current item #>
$Newheader = @{
"PDUSelector" = $identity
}
Invoke-RestMethod -Uri $Login -Method Post -SkipCertificateCheck -Body $body -ContentType application/json -Headers $Newheader
}
#Sessionids returned
$Sessionid.SessionID
This is an example of the sessionids that are returned: +KZWXna9xd2yvw== yL6FALD8n/5B2g== AZyCuSvqScOXTA== oPvKWulUCqpjzA== 8utMMVZ5o0aIag== VVY7QQcsCPPHCw== BRhvFvCLQGEkiQ== FmFMLZc/3ITQrQ== g+XrlAaImDcGAw== bXYRvNw0yRIDUw== mYTW3HtjT1Mopg== 3Bk9PX4bQXvp+g== sqZJGKO/SnrDdQ== COg4+s84jurHgA== mKL6a35Y3m5gnw== qqTjRHxtLV5sXw== skyV2hB9/dqJ8A== MolN0nt1rqBg/A== VhbAj/43I/yGyw==