我想.csv
为每个被禁用和移动的 AD 帐户创建一个文件,其中包含移动对象的$account.Distingushed
名称和移动对象的$OU.Distinguished
名称。
处理这个问题的最佳方法是什么?
$OUs | Where-Object{$excludeOUS -notcontains $_.DistinguishedName } | Foreach-Object {
$params = @{}
$params = @{
SearchBase = [String]$_.DistinguishedName
SearchScope = [String]"OneLevel"
AccountInactive = $true
TimeSpan = ([timespan]$days)
Verbose = $true
}
If($users) {
$params.Add("UsersOnly",$true)
}
ElseIf($computers) {
$params.Add("ComputersOnly",$true)
}
$accounts = Search-ADAccount @params
foreach ($account in $accounts) {
$params = @{}
$params = @{
Identity = [string]$account.DistinguishedName
Verbose = $true
}
If ($noDisable -notcontains $account.Name -and $account.ObjectClass -eq "User" ) {
Disable-ADAccount @params @whatIf
$params.Add("Description",$description)
Set-ADUser @params @WhatIf
$params.Remove('Description')
$params.Add("TargetPath", 'OU=Disabled Users,DC=test,DC=local')
Move-ADObject @params @WhatIf
# Somehow Export $account.DistinghuisedName and $OU.Distinguished name to .csv???
}
ElseIf ($noDisable -notcontains $account.Name -and $account.ObjectClass -eq "Computer") {
Disable-ADAccount @params @whatIf
$params.Add("Description",$description)
Set-ADComputer @params @WhatIf
$params.Remove('Description')
$params.Add("TargetPath", 'OU=Disabled Computers,DC=test,DC=local')
Move-ADObject @params @WhatIf
# Somehow Export $account.DistinghuisedName and $OU.Distinguished name to .csv???
}
}
}