如何用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連接微軟雲

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章