卸載Microsoft Graph PowerShell模塊
Microsoft Graph PowerShell模塊是用於管理任務的非常重要的模塊。但是,有時更新模塊存在問題,或者可能無法按預期工作。因此,您想完全刪除它,然後以新的安裝開始。在本文中,您將學習如何從系統中卸載Microsoft Graph PowerShell模塊。
Microsoft Graph PowerShell模塊(Microsoft.graph,Microsoft.graph.beta)用於管理Microsoft Entra和Microsoft 365。但是,由於模塊膨脹,版本衝突,切換到不同的工具,或僅需進行清理,您可能需要完全刪除它們。
本指南涵蓋了:
- Windows Powershell 5和PowerShell 7
- 當前用戶和所有用戶
- 通過PowerShellget和Psresourceget安裝的模塊
重要的:在Windows PowerShell和PowerShell中運行命令。當然,如果您在系統上安裝了PowerShell 7.x。
步驟1。獲取安裝的Microsoft圖形模塊
獲取Microsoft Graph PowerShell模塊的列表。在Windows PowerShell 5和PowerShell 7中運行所有命令。
了解更多:使用Microsoft Graph API和PowerShell發送電子郵件
Get-InstalledModule Microsoft.Graph* -ErrorAction SilentlyContinue
Get-InstalledPSResource Microsoft.Graph* -Scope CurrentUser -ErrorAction SilentlyContinue
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers -ErrorAction SilentlyContinue
步驟2。卸載Microsoft Graph PowerShell模塊
卸載當前用戶和所有用戶的Microsoft Graph PowerShell模塊。在Windows PowerShell 5和PowerShell 7中運行所有命令。
Get-InstalledModule Microsoft.Graph* | Uninstall-Module -AllVersions -Force
Get-InstalledPSResource Microsoft.Graph* -Scope CurrentUser | Uninstall-PSResource -Scope CurrentUser -SkipDependencyCheck
Get-InstalledPSResource Microsoft.Graph* -Scope AllUsers | Uninstall-PSResource -Scope AllUsers -SkipDependencyCheck
步驟3。手動刪除Microsoft Graph PowerShell模塊文件夾
為了確保所有內容已完全刪除,您可以以管理員的身份打開Windows PowerShell或PowerShell 7並運行腳本。
筆記:如果您的Windows操作系統以英語以外的其他語言,請更改He腳本中的文件夾的名稱。
# Get all module directories for both Windows PowerShell and PowerShell 7
$paths = @(
"$env:ProgramFilesWindowsPowerShellModules", # Windows PowerShell (all users)
"$env:USERPROFILEDocumentsWindowsPowerShellModules", # Windows PowerShell (current user)
"$env:ProgramFilesPowerShellModules", # PowerShell 7.x (all users)
"$env:USERPROFILEDocumentsPowerShellModules" # PowerShell 7.x (current user)
)
# Go through each module directory path
foreach ($path in $paths) {
Get-ChildItem -Path $path -Filter "Microsoft.Graph*" -Directory -ErrorAction SilentlyContinue |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
}
現在,一切都完全從系統中刪除了。您可以安裝Microsoft Graph PowerShell模塊。
就是這樣!
結論
您學會瞭如何卸載Microsoft Graph PowerShell模塊。刪除Windows PowerShell 5和PowerShell 7中的Microsoft Graph PowerShell模塊,以確保您不會錯過任何步驟。這樣,您確定它已被系統從系統中刪除。
您喜歡這篇文章嗎?您可能還喜歡使用PowerShell的Microsoft 365中的強制簽名用戶。不要忘記關注我們並分享這篇文章。
