Friday, August 29, 2008

Quick Powershell Templates vol1

GET MAILBOXES WITH X ACTIVESYNC POLICY

Get-CASMailbox -resultsize unlimited | Where {$_.ActiveSyncMailboxPolicy -eq "Policy Name "} | export-csv C:\outputDefault.csv

You could also replace “| export-csv C:\outputDefault.csv” with “>> file.txt” or “| Out-File c:\file.txt”


Script for identifying and pulling event logs

Param (

[string] $ID

)

Get-Eventlog Application | where {$_.EventID -eq $ID}


ALLOW SHAREPOINT / DISALLOW UNC or File shares

Set-ActiveSyncMailboxPolicy -Identity ContosoMobo -UNCAccessEnabled $false -WSSAccessEnabled $true


Pull Mailbox size and sort

Get-Mailbox -Database <mbdb> | Get-MailboxStatistics | select DisplayName,TotalItemSize | sort TotalItemSize


Change OWA time out

set-ItemProperty ‘HKLM:\SYSTEM\CurrentControlSet\Services\MSExchangeOWA’ -name TrustedClientTimeout -value 1440 -type dword


RAISED RULES QUOTA

Get-Mailbox | Where {$_.RulesQuota -ne "64KB"} | Select Name, RulesQuota


FIND USERS ANTISPAM BYPASS SET

Get-Mailbox | Where {$_.AntispamBypassEnabled -eq $True} | Select Name, AntispamBypassEnabled


FIND USERS WITH SEND ON BEHALF OF VALUE

Get-Mailbox | Where {$_.GrantSendOnBehalfTo -ne $null} | Select Name, GrantSendOnBehalfTo


FIND PEOPLE WHO’S ITEM RETENTION NOT DEFAULT

Get-Mailbox | Where {$_.UseDatabaseRetentionDefaults -eq $False} | Select Name, UseDatabaseRetentionDefaults


FIND PEOPLE HIDDEN FROM GAL

Get-Mailbox | Where {$_.HiddenFromAddressListsEnabled -eq $True} | Select Name, HiddenFromAddressListsEnabled


FIND EXCEPTIONS TO SIZE RESTRICTIONS

Get-Mailbox | Where {$_.UseDatabaseQuotaDefaults -eq $false} | Select Name, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota


PULL MAILBOX STATS FOR USERS

Get-Mailbox -Filter { (Name -eq "Name1") -or (Name -eq "Name2") -or (Name -eq "Name3") } | Get-MailboxStatistics | Format-Table


BLOCK EXTENSIONS AND DELETE WITH NO NDR

Add- AttachmentFilterEntry -Name *. ext -type FileName

Set- AttachmentFilterListConfig -Action SilentDelete

Restore RSGMAILBOX TO:

Restore-Mailbox -Identity "Name2" -RSGDatabase MyRSGDatabase -RSGMailbox "Name1" -TargetFolder Extraction -SubjectKeywords "Meeting"

Places a copy of all items where the subject contains the word "Meeting" from Name1 recovered mailbox into Name2’s mailbox under the folder named Extraction.


REMOTE MOBILE WIPE

Clear-ActiveSyncDevice -Identity WINMOBILE


RESTORE AFTER RSG LOADED

Restore-Mailbox -Identity "Name1" -RSGDatabase Alpha -RSGMailbox "Name2" -TargetFolder NameRecovery


ENABLE OUTLOOK ANYWHERE

Enable-OutlookAnywhere -Server:ExchCas1 -ExternalHostName:mail.domain.com -SSLOffLoading:$false -ExternalAuthenticationMethod:Basic

(After RPC/HTTP is installed as well as cert)


SEND AS/ RECEIVE AS

$server = Get-MailboxServer SERVERNAME

Add-ADPermission -Identity $server.Identity -User "domain\user" -ExtendedRights ("Send As", "Receive As")

OR

Get-mailboxserver <servername> | add-adpermission –user <service account> -accessrights GenericAll -extendedrights Send-As, Receive-As, ms-Exch-Store-Admin

PULL Mailbox size and sort

Get-Mailbox -Database <mbdb> | Get-MailboxStatistics | select DisplayName,TotalItemSize | sort TotalItemSize


RECOVERCMS

Stop-ClusteredMailboxServer

setup.com /RecoverCMS /CMSName:servername /CMSIPAddress:ipaddress

Setup.com /ClearLocalCMS /CMSName:servername

Enable-StorageGroupCopy servername\SG1 -StandbyMachine standbyservername

No comments: