1

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?

5
  • If you are running scripts on the VM using Custom Script Extension, you could sometimes run into an error where VM was created successfully but the script has failed. Under these conditons, the recommended way to recover from this error is to remove the extension and rerun the template again. Note: In future, this functionality would be enhanced to remove the need for uninstalling the extension. Commented Nov 29, 2017 at 18:06
  • So, I had to implement a kind of Retry Logic? Is it better to do some delay between attempts? Commented Nov 29, 2017 at 18:13
  • 1
    Try looking at the log files in C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension. That will hopefully show you more details of the error. Commented Nov 29, 2017 at 21:09
  • It looks like the "winrm create" statement is throwing an error, I changed the script and I ran it through a remote desktop connection and ir worked. Now I´m testing it again through the CustomScriptExtension. Commented Nov 29, 2017 at 21:45
  • 1
    @JohnRusk Thanks! On the latest win2k16 version, when WinRM is enabled, it´s created listening entry for all IPs on HTTP. When my script attempted to create a new entry with this setup it throws an error. Commented Nov 29, 2017 at 21:57

1 Answer 1

1

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:)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.