I tried to enable PSRemoting on a Windows VM in Azure. While it worked for some time, since last week the script doesn´t work anymore.
I ran the script using the Custom Script Extension feature:
Set-AzureRmVMCustomScriptExtension -ResourceGroupName $ResourceGroupName -VMName $VMName -Name "EnableWinRM_HTTP0" -Location $vm.Location -StorageAccountName $storageaccountname -StorageAccountKey $key -FileName "ConfigureWinRM_HTTP1.ps1" -ContainerName "scripts" -RunFile "ConfigureWinRM_HTTP1.ps1"
ConfigureWinRM_HTTP1.ps1
script is described below:
# Ensure PS remoting is enabled, although this is enabled by default for Azure VMs
Enable-PSRemoting -Force
# Create rule in Windows Firewall
New-NetFirewallRule -Name "WinRM HTTP" -DisplayName "WinRM HTTP" -Enabled True -Profile Any -Action Allow -Direction Inbound -LocalPort 5985 -Protocol TCP
# Run WinRM configuration on command line.
$cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTP"
cmd.exe /C $cmd
The virtual machine is successfully created in the same script some lines before, but when this script is part is executed, I got the following error:
Set-AzureRmVMCustomScriptExtension : Long running operation failed with status 'Failed'. Additional Info:'VM has
reported a failure when processing extension 'EnableWinRM_HTTP0'. Error message: "Finished executing command".'
ErrorCode: VMExtensionProvisioningError
ErrorMessage: VM has reported a failure when processing extension 'EnableWinRM_HTTP0'. Error message: "Finished
executing command".
StartTime: 29/11/2017 15:07:24
EndTime: 29/11/2017 15:08:14
OperationID: aa418b4a-76b4-4482-93eb-16b734009388
Status: Failed
At C:\.....\SetupVM.ps1:107 char:2
+ Set-AzureRmVMCustomScriptExtension -ResourceGroupName $ResourceGr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureRmVMCustomScriptExtension], ComputeCloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.SetAzureVMCustomScriptExtensionCommand
The monitor in the Azure Management Portal doesn´t show anything but the same error message.
Why it is not working?
Glad to hear that your issue has been resolved.
I add it to the answer, maybe it will help other community members who get the same error as you.
In windows PowerShell 3.0, the Enable-PSRemoting
cmdlet can enable windows PowerShell winrm.
The Enable-PSRemoting cmdlet performs the following operations:
1.Runs the Set-WSManQuickConfig
cmdlet, which performs the following tasks:
Starts the WinRM service.
Sets the startup type on the WinRM service to Automatic.
Creates a listener to accept requests on any IP address.
Enables a firewall exception for WS-Management communications.
Registers the Microsoft.PowerShell and Microsoft.PowerShell.Workflow session configurations, if it they are not already registered.
Registers the Microsoft.PowerShell32 session configuration on 64-bit computers, if it is not already registered.
Enables all session configurations.
Changes the security descriptor of all session configurations to allow remote access.
2.Restarts the WinRM service to make the preceding changes effective.
Hope this helps:)