I am currently trying to pull data from an Azure policy for some automation with:
(Get-AzPolicyState -Filter "ComplianceState eq 'NonCompliant'" | Where-Object {$.PolicyDefinitionReferenceId -eq "azure backup should be enabled for virtual machines_1"} | Where-Object {$.SubscriptionId -eq "0000"}).ResourceId
Type Name: System.String
Example output
/subscriptions/00/resourcegroups/rg-test/providers/microsoft.compute/virtualmachines/vm-test
/subscriptions/00/resourcegroups/rg-test2/providers/microsoft.compute/virtualmachines/vm-test2
I am confused on how I can just pull the resource group name and virtual machine name only into a variable array. The resource group name is always preceded by /resourcegroups/ and VM name is always preceded by /virtualmachines/.
Any guidance would be greatly appreciated. Thank you!
$rg,$vm= '/subscriptions/00/resourcegroups/rg-test/providers/microsoft.compute/virtualmachines/vm-test' -replace '^.*/resourcegroups/([^/]+)/.*virtualmachines/([^/]+)','$1/$2' -split '/'
– AdminOfThings