我有大约900个我需要删除的旧网站。我试图脚本的过程,它不工作,这是我的脚本:
<#Set Variables#>
$sites = Import-Csv C:Scriptstermedusers.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 Not Deleted
我确信它与日期,termdate和小于有关,但由于这是我第一次尝试使用日期,所以我不确定从这里要去哪里。任何指导将非常感激!
通过添加Get-Date
:
If ((Get-Date $Site.TermDate) -lt (Get-Date '12/31/2018'))