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" }
|
||||
"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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue