Added basic error handling to GetInfoFromUniqueId.ps1

This commit is contained in:
Oscar Pocock 2023-01-20 15:10:31 +00:00
parent 7148c51f6e
commit af6db0eaeb

View file

@ -27,19 +27,22 @@ switch($uniqueIdType){
"AROA" { $command="list-roles" }
"ASCA" { $command="list-server-certificates" }
# "ASIA" { $command="" }
default { Write-Output "Invalid 'target' value."; return}
}
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
$awsCommand = "aws iam $command"
$retunedObjects = Invoke-Expression $awsCommand | ConvertFrom-Json
Invoke-Expression $awsCommand -OutVariable succOut -ErrorVariable errOut 2>&1 >$null
if ($returnedObjects -eq $null) {
if ($errOut -ne $null) {
Write-Output "$($errOut[1].ToString())"
return
}
else {
$returnedObjects = $succOut | ConvertFrom-Json
}
$objectFound=$false
foreach($object in $retunedObjects.Policies) {
foreach($object in $returnedObjects.Policies) {
if ($objectFound -eq $true) {
break
}
@ -53,6 +56,6 @@ foreach($object in $retunedObjects.Policies) {
if ($id -eq $true) {
Write-Output "$($object.PolicyId)"
}
$objectFound=$true
return
}
}