diff --git a/GetInfoFromUniqueId.ps1 b/GetInfoFromUniqueId.ps1 index 1ccea96..454dc62 100644 --- a/GetInfoFromUniqueId.ps1 +++ b/GetInfoFromUniqueId.ps1 @@ -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 } -} +} \ No newline at end of file