嗨,第一次在这里发帖和 PS 的新手,在我们的 AD 中,我们有一个名为 Disabled 的 OU 和 12 个按月命名的子 OU,我目前有一个脚本来禁用用户删除 o365 许可证,转换为共享邮箱并移动到禁用的 OU。我想做的是将禁用的用户移动到当月的 OU 禁用操作发生。
#edit here
$NewHire = "Some.Guy"
$mobph = "123-555-1212"
$stree = "155 any ST"
$cit = "Orlando"
$sta = "Florida"
$zip = "55555"
#end Edit
$user = Get-ADUser $NewHire -Properties
mail,ProxyAddresses,Office,Company,Country,OfficePhone,streetaddress,city,state,PostalCode,MobilePhone
$user.ProxyAddresses = "SMTP:$NewHire@somedomain.com"
$user.mail = "$NewHire@somedomain.com"
$user.Office = "Remote"
$user.Company = "Company name"
$user.Country = "US"
$user.streetaddress = "$stree"
$user.city = "$cit"
$user.state = "$sta"
$user.PostalCode = "$zip"
$user.MobilePhone = "$mobph"
Set-ADUser -instance $user
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -
AllowRedirection
Import-PSSession $Session
Connect-MsolService
Get-Date -Format G
Start-Sleep -s 270
Disable-ADAccount -Identity "$NewHire"
Get-ADPrincipalGroupMembership "$NewHire" | Select Name | Export-CSV -path C:\MemberOf\$NewHire.csv -
NoTypeInformation
Get-ADUser "$NewHire" -Properties MailNickName | Set-ADUser -Replace @{MailNickName = "$NewHire"}
Get-ADUser -Identity "$NewHire" -Properties MemberOf | ForEach-Object {
$_.MemberOf | Remove-ADGroupMember -Members $_.DistinguishedName -Confirm:$false
}
Get-ADUser "$newhire" | Move-ADObject -TargetPath "OU=Disabled Accounts,OU=North
America,DC=123,DC=local"
Set-ADUser $NewHire -Replace @{msExchHideFromAddressLists=$true}
Set-MsolUserLicense -UserPrincipalName "$NewHire@somedomain.com" -RemoveLicenses "somecorp:SPE_E3"