Added basic error handling to GetInfoFromUniqueId.ps1
This commit is contained in:
parent
7148c51f6e
commit
af6db0eaeb
1 changed files with 10 additions and 7 deletions
|
@ -27,19 +27,22 @@ switch($uniqueIdType){
|
||||||
"AROA" { $command="list-roles" }
|
"AROA" { $command="list-roles" }
|
||||||
"ASCA" { $command="list-server-certificates" }
|
"ASCA" { $command="list-server-certificates" }
|
||||||
# "ASIA" { $command="" }
|
# "ASIA" { $command="" }
|
||||||
|
default { Write-Output "Invalid 'target' value."; return}
|
||||||
}
|
}
|
||||||
|
|
||||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
|
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
|
||||||
$awsCommand = "aws iam $command"
|
$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
|
return
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$returnedObjects = $succOut | ConvertFrom-Json
|
||||||
|
}
|
||||||
|
|
||||||
$objectFound=$false
|
foreach($object in $returnedObjects.Policies) {
|
||||||
|
|
||||||
foreach($object in $retunedObjects.Policies) {
|
|
||||||
if ($objectFound -eq $true) {
|
if ($objectFound -eq $true) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -53,6 +56,6 @@ foreach($object in $retunedObjects.Policies) {
|
||||||
if ($id -eq $true) {
|
if ($id -eq $true) {
|
||||||
Write-Output "$($object.PolicyId)"
|
Write-Output "$($object.PolicyId)"
|
||||||
}
|
}
|
||||||
$objectFound=$true
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue