【发布时间】:2015-07-06 12:24:54
【问题描述】:
我正在运行一个简单的脚本来让所有非活动用户(启用状态)在 60 天内未登录,如下所示。该脚本似乎在我的带有 ARS 6.7 和 WinXP 的工作站上运行良好。但是,如果我在另一个带有 ARS 6.9 和 Win7 的工作站上运行相同的脚本,则脚本的 RAM 使用量会随着时间的推移而增加,它最终会引发 OutofMemory 异常(在达到 1.5+ GB 之后)并中止。在 WinXP 工作站 (ARS v6.7) 上运行时,相同的脚本不会消耗超过 50 MB 的 RAM。我正在扫描的域非常大,有超过 550000 个帐户。我对这里的问题完全感到困惑......请帮助!
[datetime]$TodayDate = Get-Date
[datetime]$InActivityDate = $TodayDate.AddDays(-62).Date
try
{
Get-QADUser -SearchRoot $SearchOU -Service $Service -SizeLimit $SizeLimit -PageSize 1000 -Enabled -DontUseDefaultIncludedProperties -IncludedProperties SamAccountName,`
Name,ParentContainer,DN,LastLogon,WhenCreated,PasswordLastSet,employeeID,`
employeeNumber,Manager,AccountIsDisabled,co,scriptPath |`
#Filter out inactive accounts
Where-Object {$_.LastLogonTimeStamp -lt $InActivityDate} |`
Select-Object SamAccountName,Name,ParentContainer,DN,LastLogon,WhenCreated,`
PasswordLastSet,employeeID,employeeNumber,Manager,`
AccountIsDisabled,co,scriptPath | Export-Csv $OutputFile -NoTypeInformation
}
catch
{
$ErrorMessage = $_.Exception.Message
$ErrTime = Get-Date
Write-Host "Error occured:`n$ErrorMessage" -ForegroundColor Red
Write-Output "[$ErrTime] Error occured:`n$ErrorMessage" | Out-File $OutputFile -Append
}
【问题讨论】:
标签: powershell memory-leaks out-of-memory