Microsoft 365:如何使用 PowerShell 设置 OneDrive 配额
在这篇博文中,我将向您展示如何使用 PowerShell 设置 OneDrive 配额。我想说我们走吧!
首先,让我们连接到 SharePoint Online。确保您输入正确的网址和正确的用户帐户。
Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Force -AllowClobber
$cred = Get-Credential -Credential patrick@m365ps2022.onmicrosoft.com
Connect-SPOService -Url https://m365ps2022-admin.sharepoint.com -Credential $cred
接下来,我们需要找出 URL。
# Find out all OneDrive URLs
$LogFile = [Environment]::GetFolderPath("Desktop") + "\OneDriveSites.log"
Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'" |
Select-Object -ExpandProperty Url | Tee-object -FilePath $LogFile
Write-Host "File saved as $($LogFile)."
一旦我们有了 URL,我们就可以用它来设置配额。
# Configure OneDrive Quota per User
$OneDriveSite = "https://m365ps2022-my.sharepoint.com/personal/f_bizeps_m365ps2022_onmicrosoft_com"
$OneDriveStorageQuota = "2097152" # MB
$OneDriveStorageQuotaWarningLevel = "1000000" # MB
Set-SPOSite -Identity $OneDriveSite -StorageQuota $OneDriveStorageQuota -StorageQuotaWarningLevel $OneDriveStorageQuotaWarningLevel
Write-Host "Done"
就是这样。我们为用户设置了 OneDrive 配额。
但现在我们要开始真正的交易了。通过上面生成的文件,我们可以一次性为所有用户设置配额。这称为自动化。
# Automation
$urls = Get-Content $home\desktop\OneDriveSites.log
$OneDriveStorageQuota = "2097152" # MB
$OneDriveStorageQuotaWarningLevel = "1000000" # MB
foreach ($u in $urls) {
Set-SPOSite -Identity $u -StorageQuota $OneDriveStorageQuota -StorageQuotaWarningLevel $OneDriveStorageQuotaWarningLevel
}
这就是我想在这篇文章中展示的内容。我希望这有帮助。