Hi,
I have been trying to learn Azure Automation, and wanted to test running commands on Azure VMs using Invoke-AzVMRunCommand.
My goal is to get the status of multiple services that are saved in a list. Below is the code.
$VMName = "VMName"
$RGName = "ResourcegroupName"
$SubId = "XXXX-XXXX-XXXX-XXXX"
$serviceslist = ("netlogon", "dhcp")
#Create Script
echo "$serviceslist | foreach-object{ get-service $_}" >script.ps1
$out = Invoke-AzVMRunCommand -ResourceGroupName $RGName -VMName $VMName -CommandId 'RunPowerShellScript' -ScriptPath ".\script.ps1"
$out
The error:
PS C:\Users\username> $out
Value[0] :
`Code : ComponentStatus/StdOut/s