如何用PowerShell连接微软云

最近有个需求要用Powershell要看迁移任务状态,原因就是微软O365网页看状态那个地方不准确的,你刚建立的任务,十分钟没有就说同步完成了。
所以要查看状态就必须用PowerShell.
我有一个脚本,但是执行时总出错,翻译成中文就是脚本执行Policy不许可。
第一步:于是我第一步用了一个命令:
PS C:\WINDOWS\system32> Get-ExecutionPolicy -list

    Scope ExecutionPolicy
    ----- ---------------

MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine RemoteSigned

第二步: 然后我就在想,我要去微软的云去验证,这个属性应该是RemoteSigned.当时不是这样的,于是我就写了一条命令如下:

PS C:\WINDOWS\system32> Get-ExecutionPolicy -list

    Scope ExecutionPolicy
    ----- ---------------

MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine RemoteSigned

PS C:\WINDOWS\system32> Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A
PS C:\WINDOWS\system32>

第三步,其实还是不可以,然后我就找到另一个命令

Unlblock-File -path "CloudServicesShell.ps1" 想法就是把这个脚本的执行权限去掉。然后神奇的就解决了,脚本就可以执行了。

大家肯定想知道那个脚本代码是什么吧,因为有我们公司的信息,所以不方便外传,实在想要的,留言吧。

如何用PowerShell连接微软云

扫描二维码关注公众号,回复: 2090076 查看本文章

猜你喜欢

转载自blog.51cto.com/shadingyu/2140329