尝试在Windows PowerShell中运行PS1脚本来配置VM,但asjob状态被阻止 [英] Trying to run a PS1 script in a windows powershell to provision VM's, but the asjob status becomes blocked

查看:111
本文介绍了尝试在Windows PowerShell中运行PS1脚本来配置VM,但asjob状态被阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好, 

Hello all, 

希望这个问题可以快速回答,我似乎无法找到解决此问题的最佳方法。 简而言之,我的任务是编写一个脚本,使用带有-asjob
开关的New-AzureRMVM命令在Azure中配置VM。 我有一个脚本可以从CSV文件中捕获变量,并相应地在云中创建虚拟机。  

Hopefully this question can be quickly answered, I just can't seem to find the best way to resolve this issue.  Short and sweet of it is I've been tasked to write a script that provisions VMs in Azure utilizing the New-AzureRMVM command with the -asjob switch.  I have a script that captures variables from a CSV file, and creates the VMs in the cloud accordingly.  

有趣的是,如果我自己运行代码(不是通过在加载Azure模块的Windows命令提示符下执行PS1文件,它工作正常。  

The interesting thing is, if I run the code by itself (not by executing the PS1 file in a windows command prompt with the Azure modules loaded) it works fine.  

我正在使用的行是:

New-AzureRmVM -ResourceGroupName $ rgname -Location $ location -tag $ tags -VM $ vm -asjob

New-AzureRmVM -ResourceGroupName $rgname -Location $location -tag $tags -VM $vm -asjob

同样,如果我在powershell ISE中运行脚本突出显示整个脚本并说"运行选择"它有效。 如果我运行ps1脚本,当我执行get-job< jobID>时,我会得到以下内容。 | FL和它显示状态已阻止。

Again, if I run the script in powershell ISE by highlighting the entire script and say "Run Selection" it works.  If I run the ps1 script, I get the below when I do a get-job <jobID> | FL and it shows status Blocked.

PS C:\Admin\Exchange Scripts\E2016 Scripts\Scripts\Azure> get-job 5 | fl


HasMoreData          : True
Location             : localhost
StatusMessage        : Blocked
CurrentPSTransaction : 
Host                 : System.Management.Automation.Internal.Host.InternalHost
Command              : New-AzureRmVM
JobStateInfo         : Blocked
Finished             : System.Threading.ManualResetEvent
InstanceId           : f18515a1-426c-4241-bb96-af867542ca76
Id                   : 5
Name                 : Long Running Operation for 'New-AzureRmVM'
ChildJobs            : {}
PSBeginTime          : 2/7/2019 4:44:25 PM
PSEndTime            : 
PSJobTypeName        : AzureLongRunningJob`1
Output               : {}
Error                : {}
Progress             : {}
Verbose              : {}
Debug                : {[AzureLongRunningJob]: Starting cmdlet execution, setting for cmdlet 
                       confirmation required: 'True', [AzureLongRunningJob]: State change 
                       from '' to 'Running' because '', [AzureLongRunningJob]: Blocking job 
                       for ShouldMethod 'ShouldProcess', [AzureLongRunningJob]: State change 
                       from 'Running' to 'Blocked' because ''}
Warning              : {}
Information          : {}
State                : Blocked

我认为可能会将执行政策更改为不受限制,但似乎没有做任何事情。 其他人有类似的行为/知道解决方法吗?

I thought that it might be changing the execution policy to unrestricted, but that didn't seem to do anything.  Anyone else have similar behavior/know of a workaround?

谢谢!

J







推荐答案

尝试以下cmdlet

Try the below cmdlet

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass


这篇关于尝试在Windows PowerShell中运行PS1脚本来配置VM,但asjob状态被阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆