Exchange Powershell

Give regular user access to modify existing distribution group
Add-ADPermission -Identity “Marketing Department” -User “John Smith” -AccessRights WriteProperty -Properties “Member”

List enabled users First,Last,Email,Enabled,SAM,LastLogon,MDB
Get-ADUser -filter * -properties emailaddress, enabled, lastlogondate, homeMDB| ?{($_.emailaddress -ne $null) -and ($_.enabled -eq “True”)} | Select givenName,SurName,emailaddress,enabled,samaccountname,lastlogondate,homeMDB | Export-CSV C:\scripts\test.csv

Search mailboxes for subject line, and delete message
Get-Mailbox –resultsize unlimited | Search-Mailbox –SearchQuery “Subject:customer has sent you a document through Google Docs!” –DeleteContent

List number count of mailboxes per database/storagegroup
Get-Mailbox -server <servername> resultsize unlimited| Group-Object -Property:Database | Select-Object Name,Count

List all enabled users and their primary SMTP email address
Get-ADUser -filter * -properties emailaddress, enabled| ?{($_.emailaddress -ne $null) -and ($_.enabled -eq “True”)}

List enabled users whose password will expire
Get-ADUser -SearchBase “ou=Company,dc=company,dc=com” -filter* -properties emailaddress, enabled, PasswordNeverExpires | where {$_.emailaddress -ne $null} |where {$_.Enabled -eq “True”} | where {$_.PasswordNeverExpires -eq $false} | export-csv “C:\scripts\emails.csv”

Show which public folder is being used by each storage group
Get-MailboxDatabase -server EXMBX | ft storagegroup,publicfolderdatabase

List users in specific storage group/database
Get-StorageGroup -Identity “server\SG” | Get-MailboxDataBase | get-mailbox

List amount of mailboxes in each database
Get-Mailbox -resultsize unlimited | Group-Object -Property:Database | Select-Object name,count

Move users configuration to look at new mailbox server after migrating database to new server
Get-Mailbox -database “EXMBX1\CORP Storage Group\Mailbox Database” | Move-Mailbox -TargetDatabase “EXMBX3\CORP Storage Group\Mailbox Database”| -ConfigurationOnly

Hide all users in specific OU from GAL
Get-Mailbox -OrganizationalUnit “SITEOU” | Set-Mailbox -HiddenFromAddressListsEnabled $true

View Outlook clients in Online mode (not cached mode)
Get-LogonStatistics -server ServerName | where {$_.ClientMode -ne “Cached”} | select-object FullMailboxDirectoryName,UserName,Windows2000Account,ClientMode,ClientName,ClientVersion,Identity | sort-object UserName -Unique| Export-Csv -Path C:\scripts\UserCountOnlineMode.csv -NoTypeInformation

View Exchange last backup status
Get-MailboxDatabase -Status | ft storagegroup,name,last* -auto

List user accounts in specific OU
Get-ADUser -Filter * -SearchBase ‘OU=VDI Users,OU=Users,OU=Site,OU=Company,DC=Company,DC=com’ | FT Name > C:\vdi.txt

Forcefully Purge Disconnected Exchange mailboxes
Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid

Remove-Mailbox -Database ‘Storage Group\Mailbox Database’ -StoreMailboxIdentity 2bae667a-7660-4b84-a105-07ecb854be6e

Search list of computers for specific software

Get-Content C:\computers.txt
$list | ForEach-Object{
$computer = $_
Get-WmiObject -Class Win32_Product -ComputerName $computer |
Select-Object -Property Name |
Sort-Object Name |
Where-Object{$_.Name -match “Cylance”} |
Add-Member -MemberType NoteProperty -Name “Computer” -Value $computer -passthru
} | Export-Csv -NoTypeINformation -Path C:\Cylance.csv

findsoftware

Disable OWA and ActiveSync features for list of users in .txt file

# This script will read a local txt from Exchange server in the directory listed on line #3
# Logs folder must be existant or script will error as it does not create the folder
$SourceFile = “c:\Scripts\DisableActiveSync-DisableOWA\Users.txt”
$LogFile = “c:\Scripts\DisableActiveSync-DisableOWA\Logs\DisableActiveSyncLog.txt”

$UserList = Get-Content $SourceFile
foreach($user in $UserList)
{
$message = “Disabling ActiveSync and OWA for user -&gt; ” + $user
write-output $message | out-file -filePath $LogFile -append -noClobber
Set-CASMailbox -Identity $user -ActiveSyncEnabled $false
Set-CASMailbox -Identity $user -OWAEnabled $false

if($error.Count -ne 0)
{
$message = “User ” + $user + ” ActiveSync settings failed to change”
write-output $message | out-file -filePath $LogFile -append -noClobber
$message = “Error:::: ” + $error[0].ToString()
write-output $message | out-file -filePath $LogFile -append -noClobber
$error.Clear()
}

owa-as-disable

Stollfus Tech Blog

WordPress Appliance - Powered by TurnKey Linux