运行 Azure VM 上的脚本
Run script on Azure VM
我尝试在 Azure 中的 Windows VM 上启用 PSRemoting。虽然它工作了一段时间,但自上周以来脚本不再工作了。
我 运行 使用自定义脚本扩展功能的脚本:
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
脚本说明如下:
# 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
虚拟机在前面几行的同一个脚本中成功创建,但是当这个脚本执行到一部分时,我得到了以下错误:
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
Azure 管理门户中的监视器只显示相同的错误消息。
为什么它不起作用?
很高兴得知您的问题已得到解决。
我把它添加到答案中,也许它会帮助其他和你有同样错误的社区成员。
在 windows PowerShell 3.0 中,Enable-PSRemoting
cmdlet 可以启用 windows PowerShell winrm。
Enable-PSRemoting cmdlet 执行以下操作:
1.Runs Set-WSManQuickConfig
cmdlet,执行以下任务:
启动 WinRM 服务。
将 WinRM 服务的启动类型设置为自动。
创建一个侦听器以接受对任何 IP 地址的请求。
为 WS-Management 通信启用防火墙例外。
注册 Microsoft.PowerShell 和 Microsoft.PowerShell。工作流会话配置,如果它们尚未注册。
在 64 位计算机上注册 Microsoft.PowerShell32 会话配置(如果尚未注册)。
启用所有会话配置。
更改所有会话配置的安全描述符以允许远程访问。
2.Restarts WinRM 服务使前面的更改生效。
希望对您有所帮助:)
我尝试在 Azure 中的 Windows VM 上启用 PSRemoting。虽然它工作了一段时间,但自上周以来脚本不再工作了。
我 运行 使用自定义脚本扩展功能的脚本:
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
脚本说明如下:
# 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
虚拟机在前面几行的同一个脚本中成功创建,但是当这个脚本执行到一部分时,我得到了以下错误:
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
Azure 管理门户中的监视器只显示相同的错误消息。
为什么它不起作用?
很高兴得知您的问题已得到解决。
我把它添加到答案中,也许它会帮助其他和你有同样错误的社区成员。
在 windows PowerShell 3.0 中,Enable-PSRemoting
cmdlet 可以启用 windows PowerShell winrm。
Enable-PSRemoting cmdlet 执行以下操作:
1.Runs Set-WSManQuickConfig
cmdlet,执行以下任务:
启动 WinRM 服务。
将 WinRM 服务的启动类型设置为自动。
创建一个侦听器以接受对任何 IP 地址的请求。
为 WS-Management 通信启用防火墙例外。
注册 Microsoft.PowerShell 和 Microsoft.PowerShell。工作流会话配置,如果它们尚未注册。
在 64 位计算机上注册 Microsoft.PowerShell32 会话配置(如果尚未注册)。
启用所有会话配置。
更改所有会话配置的安全描述符以允许远程访问。
2.Restarts WinRM 服务使前面的更改生效。
希望对您有所帮助:)