Kelly Garcia
asked on
Powershell Functions
Hi Guys,
I have written this function in powershell, can you think of better ways of writing this?:
thank you in advance.
Regards,
Kay
I have written this function in powershell, can you think of better ways of writing this?:
function LogsToLogAnalytics ($resource,$categories,$Log){
Process {
Try {
Set-AzureRmDiagnosticSetting -Name $DiName -ResourceID $($resource.ResourceID) -WorkspaceId $($LogAnalytics.ResourceId) -enabled $en -Categories $categories -ErrorAction Stop >> $Log
if ($en){write-output "Diagnostics Setting Successfully Enabled for $($Resource.name)"}
else { Write-Output "Diagnostics Setting Disabled for $($Resource.name)" }
}
Catch {
Write-Output "Caught an exception on $($Resource.name)"
Write-Output "Exception Type: $($_.Exception.GetType().FullName)"
Write-Output "Exception Message: $($_.Exception.Message)"
Write-Output " "
}
}
}
$KV = Get-AzureRmResource | Where-Object {$_.resourcetype -eq "Microsoft.KeyVault/vaults" }
$KV | ForEach-Object {
LogsToLogAnalytics -Resource $_ -Categories AuditEvent -Log $KeyVaultConfigLog
} #endforeach
thank you in advance.
Regards,
Kay
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER