Advertisement
Guest User

Untitled

a guest
Aug 31st, 2018
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Username = "name@company.com"
  2. $PasswordPath = "c:\scripts\password.txt"
  3.  
  4. # Read the password from the file and convert to SecureString
  5. Write-Host "Getting password from $passwordpath"
  6. $SecurePassword = Get-Content $PasswordPath | ConvertTo-SecureString
  7.  
  8. # Build a Credential Object from the password file and the $username constant
  9. $Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
  10.  
  11. # Open a session to O365
  12. $O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
  13. import-pssession $O365session
  14.  
  15. # Recurse through the Projects Public Folder and mail-enable those that aren't currently mail enabled, and mail-disable the top level folders.
  16.  
  17. $folders = get-publicfolder "\TEST" -recurse -resultsize unlimited
  18.  
  19. foreach($folder in $folders)
  20. {
  21.     $owners = Get-PublicFolderClientPermission -identity $folder.identity | ? {$_.accessrights -eq "Owner" }
  22.     foreach($owner in $owners)
  23.     {
  24.         Remove-PublicFolderClientPermission -Identity $folder.identity -user "$($owner.user)" -confirm:$false
  25.         Add-PublicFolderClientPermission -Identity $folder.identity -user "$($owner.user)" -AccessRights CreateItems,ReadItems,CreateSubfolders,FolderOwner,FolderContact,FolderVisible,EditOwnedItems,EditAllItems
  26.     }
  27. }
  28.  
  29. Remove-PSSession $O365Session
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement