Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $termlist = $env:termlist
- $accesslist = $env:accesslist
- $forward = $env:forward
- $365user = "blah@blah.org"
- $adUser = "Blah\jenkins-admin"
- $adPass = Get-Content c:\path\credentials.txt | ConvertTo-SecureString -AsPlainText -Force
- $365CRED = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $365user, $adPass
- $ADCRED = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adUser, $adPass
- #Split the parameter by ; delimiter
- $terms = $termlist -split ";"
- #Get the AD users based on their UPN (e-mail), disable the account(s), move them to deactivated OU
- foreach ($termee in $terms) {
- $disabledUser = Get-ADUser -Filter "UserPrincipalName -eq '$termee'" -Credential $ADCRED
- $folderName = $disabledUser.SamAccountName
- Disable-ADAccount -Identity $disabledUser -Credential $ADCRED
- Move-ADObject -Identity $disabledUser -TargetPath "OU=Deactivated Users,DC=contoso,DC=com" -Credential $ADCRED
- Remove-Item -Path \\austin\user$\$folderName -Recurse -Force -Credential $ADCRED
- }
- #Establish remote PS session
- $SESSION = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $365CRED -Authentication Basic -AllowRedirection
- Import-PSSession $SESSION
- Connect-MsolService -Credential $365CRED
- #Set Mailbox(es) to Shared instead of User
- foreach ($termee in $terms) {
- Get-Mailbox -identity $termee | set-mailbox -type Shared
- #If -accesslist parameter is specified, add full access permissions to shared mailbox based on specified user(s)/group
- if($accesslist -ne $null) {
- $access = $accesslist -split ";"
- foreach($addAccess in $access) {
- Add-MailboxPermission $termee -User $addAccess -AccessRights FullAccess
- }
- }
- #Pull down list of O365 licenses for a user, then remove them
- (get-MsolUser -UserPrincipalName $termee).licenses.AccountSkuId |
- foreach{
- Set-MsolUserLicense -UserPrincipalName $termee -RemoveLicenses $_
- }
- #Establish a 365 day litigation hold
- Set-Mailbox $termee -LitigationHoldEnabled $true -LitigationHoldDuration 365
- #If -forward parameter is specified, forwards the email intended for the mailbox to that specified user
- if($forward -ne $null) {
- Set-Mailbox $termee -ForwardingAddress $forward -DeliverToMailboxAndForward $False
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement