Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefajers authored Dec 16, 2024
1 parent 8a73322 commit 372cddb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
56 changes: 31 additions & 25 deletions src/internal/functions/Get-AzOpsResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,39 @@

process {
Set-AzOpsContext -ScopeObject $ScopeObject
switch ($ScopeObject.Resource) {
# Check if the resource exist
'locks' {
$resource = Get-AzResourceLock -Scope "/subscriptions/$($ScopeObject.Subscription)" -ErrorAction SilentlyContinue | Where-Object { $_.ResourceID -eq $ScopeObject.Scope }
}
'policyAssignments' {
$resource = Get-AzPolicyAssignment -Id $scopeObject.Scope -ErrorAction SilentlyContinue
}
'policyDefinitions' {
$resource = Get-AzPolicyDefinition -Id $scopeObject.Scope -ErrorAction SilentlyContinue
}
'policyExemptions' {
$resource = Get-AzPolicyExemption -Id $scopeObject.Scope -ErrorAction SilentlyContinue
}
'policySetDefinitions' {
$resource = Get-AzPolicySetDefinition -Id $scopeObject.Scope -ErrorAction SilentlyContinue
}
'roleAssignments' {
$resource = Invoke-AzRestMethod -Path "$($scopeObject.Scope)?api-version=2022-04-01" | Where-Object { $_.StatusCode -eq 200 }
}
'resourceGroups' {
$resource = Get-AzResourceGroup -Id $scopeObject.Scope -ErrorAction SilentlyContinue
}
default {
$resource = Get-AzResource -ResourceId $ScopeObject.Scope -ErrorAction SilentlyContinue
try {
switch ($ScopeObject.Resource) {
# Check if the resource exist
'locks' {
$resource = Get-AzResourceLock -Scope "/subscriptions/$($ScopeObject.Subscription)" -ErrorAction SilentlyContinue | Where-Object { $_.ResourceID -eq $ScopeObject.Scope }
}
'policyAssignments' {
$resource = Get-AzPolicyAssignment -Id $scopeObject.Scope -ErrorAction SilentlyContinue
}
'policyDefinitions' {
$resource = Get-AzPolicyDefinition -Id $scopeObject.Scope -ErrorAction SilentlyContinue
}
'policyExemptions' {
$resource = Get-AzPolicyExemption -Id $scopeObject.Scope -ErrorAction SilentlyContinue
}
'policySetDefinitions' {
$resource = Get-AzPolicySetDefinition -Id $scopeObject.Scope -ErrorAction SilentlyContinue
}
'roleAssignments' {
$resource = Invoke-AzRestMethod -Path "$($scopeObject.Scope)?api-version=2022-04-01" | Where-Object { $_.StatusCode -eq 200 }
}
'resourceGroups' {
$resource = Get-AzResourceGroup -Id $scopeObject.Scope -ErrorAction SilentlyContinue
}
default {
$resource = Get-AzResource -ResourceId $ScopeObject.Scope -ErrorAction SilentlyContinue
}
}
}
catch {
Write-AzOpsMessage -LogLevel InternalComment -LogString 'Get-AzOpsResource.Failed' -LogStringValues $_
return
}
if ($resource) {
return $resource
}
Expand Down
2 changes: 2 additions & 0 deletions src/localized/en-us/Strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
'Get-AzOpsPolicyExemption.ResourceGroup' = 'Retrieving Policy Exemption for Resource Group {0}' # $ScopeObject.ResourceGroup
'Get-AzOpsPolicyExemption.Subscription' = 'Retrieving Policy Exemption for Subscription {0} ({1})' # $ScopeObject.SubscriptionDisplayName, $ScopeObject.Subscription

'Get-AzOpsResource.Failed' = 'Failed retrieving resource with error: {0}' # $_

'Get-AzOpsResourceLock.ResourceGroup' = 'Retrieving Resource Locks for Resource Group {0}' # $ScopeObject.ResourceGroup
'Get-AzOpsResourceLock.Failed' = 'Failed retrieving Resource Locks {0}' # $_
'Get-AzOpsResourceLock.Subscription' = 'Retrieving Resource Locks for Subscription {0} ({1})' # $ScopeObject.SubscriptionDisplayName, $ScopeObject.Subscription
Expand Down

0 comments on commit 372cddb

Please sign in to comment.