I am trying to use the Invoke-AzVMRunCommand
on a VM in my Azure subscription.
My powershell looks like this
Invoke-AzVMRunCommand -VMName $vm.Name -ResourceGroupName $vm.ResourceGroupName -CommandId 'RunPowerShellScript' -ScriptPath $scriptPath
With the script in my $scriptPath
looking like this
Get-NetFirewallProfile | ConvertTo-Csv
When running this however, the response seems to tell me that the windows firewall is enabled, even though I know for a fact it is not.
The ConvertTo-Csv
is required for other parts of my script to function as needed, as Invoke-AzVMRunCommand
returns a string object, which isn’t too useful. Even without this however I still don’t get the correct response
Does anybody know of any reason as to why this might be?
2
Answers
So the commands I was running check different areas of the registry from the GUI.
GUI: HKEY_LOCAL_MACHINESOFTWAREPoliciesMicrosoftWindowsFirewallDomainProfile
CMDLETS: HKLM:SYSTEMCurrentControlSetServicesSharedAccessParametersFirewallPolicyStandardProfile
This is where the issue came from.
If you have this issue, but sure to check both registry entries
To check the status of the
firewall
status from remote computer withInvoke-AzVMRunCommand
, you can use the below command in your script to show the details in a table format, instead of usingGet-NetFirewallProfile | ConvertTo-Csv
Here is the result of above command.
If you want to check all the details of the
Windows firewall
, you can use the following command:Alternatively, if you only need to check the name and the firewall status, you can use the command above.
Script path
Here is a script that executes
scriptpath
on a remote machine.Result:
Firewall details have been exported to CSV