Home > AD, Exchange, Powershell > Powershell: Quickies

Powershell: Quickies

Some single line goodies I keep documented. Nothing earth shattering, but good in a pinch!
###———— Set the “require sending users to authenticate” attribute on a DL
###———— Example: on DL-R2P-55481 allow non Company exchange users to send to this DL
Set-DistributionGroup DL-R2P-55481 -RequireSenderAuthenticationEnabled $False
###———— Set the accept from attribute on a DL
###———— Example: Get all R2P DLs and only allow Richard to send to them
get-group dl-r2p-* | Set-DistributionGroup -AcceptMessagesOnlyFrom richard@company.com
###———— parse mailboxes for a delegate
###———— Example: Search for all mailboxes Jon Smith is a delegate for
Get-Mailbox -resultsize unlimited | where { $_.grantsendonbehalfto -match {Smith, Jon} }
###———— Runs the nightly maintenance on a DB to allow disconnected mailboxs to show up
###———— Example: start the cleanup process on Exmail1 SG05 (it’s easiest to run get-mailboxdatabse and copy and paste the DB name, they’re long!!)
Clean-MailboxDatabase “Ex-mail1\EX-MAIL1-SG05-MS01”
###———— To get a list of all databases names
Get-mailboxdatabase | fl name
###———— Search for disconnected mailboxes
###———— Example: Look for all disconnected mailboxes on exmail2
Get-MailboxStatistics -Server exmail2 | where { $_.DisconnectDate -ne $null } | select DisplayName,DisconnectDate
###———— “exmerge” data directly from one mailbox to another and a sub-folder
###———— Example: move all my mail to herb in a folder called Larrys Termed email
Export-Mailbox larry@company.com -TargetMailbox herb@company.com -TargetFolder “Larrys Termed email”
###———— Find user by wildcard on email address and is mailbox enabled
###———— Example: Find all users with email address field and has a mailbox attached.
Get-User -Filter {(windowsemailaddress -like ‘larry.hinz*’) -and (recipientType -eq ‘Usermailbox’)}
###———— Find all users with dialin (VPN) accesss set to true
###———— Example: Find all users with VPN access in Company.local and export to CSV
Get-QADUser -ObjectAttributes @{msNPAllowDialin=$true} | Select-Object name,email | Export-Csv C:\Users\larry\Desktop\VPN.csv
###———— Find all enabled users and export
###———— Example:
Get-QADUser | where {$_.accountisdisabled -eq “false”} | Select-Object firstname,lastname,samaccountname | Export-Csv c:\output.csv
###———— Set the “require sending users to authenticate” attribute on a DL
###———— Example: on DL-R2P-55481 allow non Company exchange users to send to this DL
Set-DistributionGroup DL-R2P-55481 -RequireSenderAuthenticationEnabled $False
###———— Set the accept from attribute on a DL
###———— Example: Get all R2P DLs and only allow Richard to send to them
get-group dl-r2p-* | Set-DistributionGroup -AcceptMessagesOnlyFrom richard@company.com
###———— parse mailboxes for a delegate
###———— Example: Search for all mailboxes Jon Smith is a delegate for
Get-Mailbox -resultsize unlimited | where { $_.grantsendonbehalfto -match {Smith, Jon} }
###———— Runs the nightly maintenance on a DB to allow disconnected mailboxs to show up
###———— Example: start the cleanup process on Exmail1 SG05 (it’s easiest to run get-mailboxdatabse and copy and paste the DB name, they’re long!!)
Clean-MailboxDatabase “Ex-mail1\EX-MAIL1-SG05-MS01”
###———— To get a list of all databases names
Get-mailboxdatabase | fl name
###———— Search for disconnected mailboxes
###———— Example: Look for all disconnected mailboxes on exmail2
Get-MailboxStatistics -Server exmail2 | where { $_.DisconnectDate -ne $null } | select DisplayName,DisconnectDate
###———— “exmerge” data directly from one mailbox to another and a sub-folder
###———— Example: move all my mail to herb in a folder called Larrys Termed email
Export-Mailbox larry@company.com -TargetMailbox herb@company.com -TargetFolder “Larrys Termed email”
###———— Find user by wildcard on email address and is mailbox enabled
###———— Example: Find all users with email address field and has a mailbox attached.
Get-User -Filter {(windowsemailaddress -like ‘larry.hinz*’) -and (recipientType -eq ‘Usermailbox’)}
###———— Find all users with dialin (VPN) accesss set to true
###———— Example: Find all users with VPN access in Company.local and export to CSV
Get-QADUser -ObjectAttributes @{msNPAllowDialin=$true} | Select-Object name,email | Export-Csv C:\Users\larry\Desktop\VPN.csv
###———— Find all enabled users and export
###———— Example:
Get-QADUser | where {$_.accountisdisabled -eq “false”} | Select-Object firstname,lastname,samaccountname | Export-Csv c:\output.csv
Advertisements
Categories: AD, Exchange, Powershell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: