public/Enable-AzureDSCNodeDiagnostics.ps1
function Enable-AzureDSCNodeDiagnostics { [CmdletBinding()] Param ( [Parameter(Mandatory=$false)] [bool]$enabled = $true, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$workspaceid, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$subscriptionName ) Process { # check to see if local token exists (ran Login-AzureRMAccount) if (($null -eq (Get-AzureRmContext).Account)) { Write-Warning "Please run < Login-AzureRMAccount > first to create a session token...exiting." break } # Get subscription name Try { Select-AzureRmSubscription -SubscriptionName $subscriptionName -ErrorAction Stop -Verbose | Out-Null } Catch { $error[0].Exception break } $results = @() $automation_accounts = Find-AzureRmResource -ResourceType "Microsoft.Automation/automationAccounts" foreach ($a in $automation_accounts) { Try { $dsc_nodes = Get-AzureRmAutomationDscNode -ResourceGroupName "$($a.resourcegroupname)" -AutomationAccountName "$($a.name)" -ErrorAction Stop -Verbose } Catch { $error[0].Exception break } if ($null -ne $dsc_nodes) { Try { $op = Set-AzureRmDiagnosticSetting -ResourceId "$($a.ResourceId)" -WorkspaceId $workspaceid -Enabled $enabled -Categories 'DSCNodeStatus' -ErrorAction Stop -Verbose $results += $op } Catch { $error[0].Exception break } } } return $results } # end process block } # end function |