Azure automation &引用;找不到文件";调用azurermvmrun命令
使用Azure automation、powershell runbook,我尝试在VM内执行脚本Azure automation &引用;找不到文件";调用azurermvmrun命令,azure-automation,Azure Automation,使用Azure automation、powershell runbook,我尝试在VM内执行脚本 $ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection' Add-AzAccount -ServicePrincipal -TenantId $ServicePrincipalConnection.TenantId -ApplicationId $ServicePrincipalConn
$ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection'
Add-AzAccount -ServicePrincipal -TenantId $ServicePrincipalConnection.TenantId -ApplicationId $ServicePrincipalConnection.ApplicationId -CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint
$rgname ="rg-name"
$vmname ="vmName"
$ScriptToRun = "c:\temp\shutdown.ps1" #file exists in the VM
Invoke-AzVMRunCommand -ResourceGroupName $rgname -Name $vmname -CommandId 'RunPowerShellScript' -ScriptPath $ScriptToRun
但是我得到了这个错误
“找不到文件'c:\temp\shutdown.ps1'。”
我发现了一个类似的问题,但答案令人困惑
“我发现有问题的文件需要存在于本地计算机上
机器——不是远程机器。”
我们这里只讨论一个VM,所以不确定本地机器和远程机器的含义。我们需要将文件加载到一个对象中,然后像这样运行它,最后将其删除
Out-File -InputObject $ScriptToRun -FilePath ScriptToRun.ps1
Invoke-AzVMRunCommand -ResourceGroupName $rgname -Name $vmname -CommandId 'RunPowerShellScript' -ScriptPath ScriptToRun.ps1
Remove-Item -Path ScriptToRun.ps1