As an exchange administrator, you may occassionally need to know which mailboxes a particular user has Full Mailbox Access or Send As permissions to. This may be required as part of an audit, or to simply copy an existing users permissions for a new user you are setting up/creating.
The script below helps to accomplish this, as there is no in-built/easy way to view which mailboxes a particular user has access to - ie. Full Mailbox Access, or Send As permissions
First you need to specify the user whose existing access we are checking, using the $user variable. We use the wildcard "*" to essentially match any name that contains what is between the *'s - the users first name, last name or alias should work.
$user = "*peter*"
Next we run the get-mailbox cmdlet against all mailboxes in exchange, to query the permissions on each mailbox to see if this user exists in the respective permissions list.
There are two separate commands to do this - one to check for Full Access permissions, and the other to check for Send As permissions
get-mailbox -resultsize unlimited | get-mailboxpermission | where {$_.user -like $user} | select Identity, AccessRights
get-mailbox -resultsize unlimited | get-adpermission | where {($_.user -like $user) -and ($_.ExtendedRights -like "*Send-As*")} | select Identity, ExtendedRights
If any matches are found, the results will be displayed showing their Identity (ie. name) and the Access Rights level they have
Hints, tips, thoughts & findings on the world of Technology & Scripting
Showing posts with label access. Show all posts
Showing posts with label access. Show all posts
Wednesday, 14 September 2016
Tuesday, 29 January 2013
File Locked After Sending SMTP Email with Powershell
In my previous blog post about sending emails with Powershell, I mentioned a problem where files that you attach to an email become locked until the instance of Powershell you are running has exited completely. So if you run a script through Powershell ISE that attaches a file to an email, that file will remain locked until you exit Powershell ISE.
If the file is locked by Powershell, you will get an error/warning message similar to the following if you try to modify it in any way;
The process cannot access the file 'c:\filename.txt' because it is being used by another process
By using the following command, you can ensure that Powershell 'disposes' of the email message once it has been sent and does not continue to 'lock' any files you attach and send via email;
$mailmessage.dispose()
Note: this is assuming that $MailMessage = New-Object system.net.mail.mailmessage
If the file is locked by Powershell, you will get an error/warning message similar to the following if you try to modify it in any way;
The process cannot access the file 'c:\filename.txt' because it is being used by another process
By using the following command, you can ensure that Powershell 'disposes' of the email message once it has been sent and does not continue to 'lock' any files you attach and send via email;
$mailmessage.dispose()
Note: this is assuming that $MailMessage = New-Object system.net.mail.mailmessage
Subscribe to:
Posts (Atom)