尝试使用脚本删除 Sharepoint Mysites
Attempting to remove Sharepoint Mysites with a script
我有大约 900 个旧的 mysite 站点需要删除。我试图编写该过程的脚本,但它不起作用,这是我的脚本:
<#Set Variables#>
$sites = Import-Csv C:\Scripts\termedusers.csv
$Date = Get-Date -Format 'MM/dd/yyyy'
<#Confirm Import#>
$sites.count
<#Remove Sites of employees who were termed over 3 years ago#>
ForEach ($site in $sites) {
Get-SPSite -Identity $Site.SiteName
If ($Site.TermDate -lt 12/31/2018)
{
Write-Host "Removing Site:" $Site.SiteName -ForegroundColor Green -Object | Remove-SPSite -Identity $site.SiteName -GradualDelete -Confirm:$False
}
Else
{
Write-Host $Site.SiteName "Not Deleted"
}
}
但是当我 运行 脚本时,我只是得到 https://sitename.com/mysite/domain_user_name 未删除
我确信它与日期、termdate 和小于有关,但由于这是我第一次尝试使用日期,所以我不太确定从这里该何去何从。任何指导将不胜感激!
确保通过添加 Get-Date
:
来比较日期
If ((Get-Date $Site.TermDate) -lt (Get-Date '12/31/2018'))
我有大约 900 个旧的 mysite 站点需要删除。我试图编写该过程的脚本,但它不起作用,这是我的脚本:
<#Set Variables#>
$sites = Import-Csv C:\Scripts\termedusers.csv
$Date = Get-Date -Format 'MM/dd/yyyy'
<#Confirm Import#>
$sites.count
<#Remove Sites of employees who were termed over 3 years ago#>
ForEach ($site in $sites) {
Get-SPSite -Identity $Site.SiteName
If ($Site.TermDate -lt 12/31/2018)
{
Write-Host "Removing Site:" $Site.SiteName -ForegroundColor Green -Object | Remove-SPSite -Identity $site.SiteName -GradualDelete -Confirm:$False
}
Else
{
Write-Host $Site.SiteName "Not Deleted"
}
}
但是当我 运行 脚本时,我只是得到 https://sitename.com/mysite/domain_user_name 未删除
我确信它与日期、termdate 和小于有关,但由于这是我第一次尝试使用日期,所以我不太确定从这里该何去何从。任何指导将不胜感激!
确保通过添加 Get-Date
:
If ((Get-Date $Site.TermDate) -lt (Get-Date '12/31/2018'))