Friday 6 July 2012

Adding few more Exchange Powershell Scripts...

To get the list of mailbox users Statistics:


Get-content C:\Users.txt | Get-MailboxStatistics | select displayname,LastLogonTime, LastLogoffTime,LastLoggedOnUserAccount,database, TotalItemSize> c:\result.txt


TXT file Format:
Test Mail
Test Mail1


You can add some more stings if you need: ItemCount, DisconnectDate, DeletedItemCount


To find Manual quota is defined or not for Bulk users:


Copy below script into txt file and change into .ps1
----------------------------
$CSV = Import-Csv "C:\Powershell\quota.csv"
$csv | Foreach {
$Indentity = $_.Alias
get-mailbox -Identity $_.Alias | Where {$_.UseDatabaseQuotaDefaults -eq $false}
}
--------------------------
CSV Format:
Alias
Test.user1
Test.user2




To get the list of mailbox users Statistics:


Get-content C:\Users.txt | Get-MailboxStatistics | select displayname,LastLogonTime, LastLogoffTime,LastLoggedOnUserAccount,database, TotalItemSize> c:\result.txt


TXT file Format:
Test Mail
Test Mail1


You can add below stings if you need: ItemCount, DisconnectDate, DeletedItemCount




To find Manual quota is defined or not for Bulk users:


Copy below script into txt file and change into .ps1


------------------------------
$CSV = Import-Csv "C:\Powershell\quota.csv"
$csv | Foreach {
$Indentity = $_.Alias
get-mailbox -Identity $_.Alias | Where {$_.UseDatabaseQuotaDefaults -eq $false}
}
-----------------------------


CSV Format:
Alias
Test.User1
Test.user2


Get Database Quota Result for all Mailbox servers:
Get-MailboxDatabase | Select-Object ServerName,Name,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota | Sort-Object Name | Export-Csv d:\DatabaseLimits.csv –NoTypeInformation




Apply Quota for Bulk Database:
Copy below to TXT file and convert into .PS1
----------------
$csv = import-csv "C:\Powershell\DB\DB.csv"
$csv | Foreach {
Set-MailboxDatabase-Identity $_.DB -IssueWarningQuota 900MB-ProhibitSendQuota 1024MB-ProhibitSendReceiveQuota 8192MB
}
---------------
CSV Format:
DB
EXCH01\SG1\MBXStore1
EXCH02\SG2\MBXStore2
EXCH03\SG3\MBXStore3


ActiveSync users list with Policyname and server:


Get-CASMailbox -Filter {ActiveSyncMailboxPolicy -eq $ActiveSyncPolicyName} |ft Displayname, ActiveSyncMailboxPolicy, Servername


Active Sync users search by Policy Name:
Get-CASMailbox | where{$_.activesyncmailboxpolicy -match“Default”} | ft Displayname



Hope this help!!!





Thursday 7 June 2012

Active Directory Quest PowerShell command line....


Below are the few single line Quest PowerShell command s which will help you for routine Active Directory Task.

 Note: This should run on Active Directory Quest PowerShell Command Prompt



Move the Disable users or any user to different OU:


Get-Content "C:\Powershell\DisableAccounts\Duser.txt" | Move-QADObject –NewParentContainer  "OU=Disabled Accounts,DC=lab,DC=com"



Search the Disable users in Entire AD to move to Disbaled OU or Where you want:

Get-QADuser -SizeLimit 0 -ldap "(userAccountControl:1.2.840.113556.1.4.803:=2)" | Move-QADObject -NewParentContainer "OU=Disabled Computers,DC=lab01,DC=com"


To Create Bulk AD account with out Mailbox Users:

Import-CSV C:\NewUser1.csv | ForEach-Object -Process {New-QADUser -Name $_.UserName -FirstName $_.FirstName -LastName $_.LastName-SamAccountName $_.sAMAccountName -UserPrincipalName $_.UPN -ou $_.OU -UserPassword $_.Password}


CSV Format: 
SamAccountName,UPN,OU,Password
Test.Cloud,Test.Cloud@lab.com,"OU=Users,DC=lab,DC=com",Passw0rd12




OU
Password


TO Get AD USER DETAILS:




For whole Domain:

QADUser -SearchRoot "lab.com/" -IncludeAllProperties -sizelimit 0 | select name,LastLogonTimestamp,mail,PasswordNeverExpires,accountExpires,createTimeStamp,PasswordLastSet,userAccountControl | Export-Csv d:\Reports\result.csv

For any OU:
QADUser -SearchRoot "lab.com/hult" -IncludeAllProperties -sizelimit 0 | select name,LastLogonTimestamp,mail,PasswordNeverExpires,accountExpires,createTimeStamp,PasswordLastSet,userAccountControl | Export-Csv d:\Reports\result.csv



For any set of users:

Get-Content "c:\userlist.txt" | Get-QADUser -IncludeAllProperties -sizelimit 0 | select name,LastLogonTimestamp,mail,PasswordNeverExpires,accountExpires,createTimeStamp,PasswordLastSet,userAccountControl | Export-Csv d:\Reports\result.csv

Some more Exchange Scripts.............


Script to delete contents from Mailbox:

Note: Before running this script gives your Exchange admin account as Full Access Permission into both source and target mailbox. Change the target/source mailbox, subjectkeywords and start date according to your requirement.

Get-content C:\Powershell \users1.txt | get-mailbox | Export-Mailbox -TargetMailbox test.cloud@contoso.com -IncludeFolders "\Inbox","\Sent Items" -TargetFolder target-SubjectKeywords "exchange" -StartDate "09/14/2011"-DeleteContent -confirm: $false

CSV File format:

Alias

Test.cloud1


To display the Dismount user immediately in EMC console:

clean-mailboxdatabase-identity "RSG2"

clean-mailboxdatabase-server “Exch07”


Command to create RSG/SG in EX2K7:

New-StorageGroup –Server EXCH01 –LogFolderPath“H:\Log15" –Name “Recovery Storage Group” –SystemFolderPath “H:\Log15” –Recovery

New-MailboxDatabase–MailboxDatabaseToRecover “MBXStore01” –StorageGroup “EXCH01\Recovery Storage Group” –EDBFilePath “H:\DB01\MBXStore01.edb”

Set-MailboxDatabase -Identity "EXCH01\Recovery Storage Group\MBXStore01" -AllowFileRestore $true

Mount-Database –Identity “EXCH01\Recovery Storage Group\MBXStore01”



How to remove DOTS from powershell result

use | ft -wrap

Ex:

Get-Mailbox-ResultSize:Unlimited | ForEach {Get-ActiveSyncDeviceStatistics-Mailbox:$_.Identity} |ft -wrap identity,devicetype,DeviceUserAgent,LastSuccessSync> c:\user.csv














Hope this helps.

Expect more!!

Tuesday 5 June 2012

Exchange single PowerShell command line tips and tricks


Below are some of the single line PowerShell commands which will help you routine Exchange tasks.

 
To find Deleted Mailboxes from Exchange Server:

Get-MailboxStatistics -Server Exch01| where { $_.DisconnectDate -ne $null } | select DisplayName,DisconnectDate

To Change Primary SMTP for bulk Users:

Import-Csv "C:\Powershell\user.csv" | foreach {
Set-Mailbox $_.alias -PrimarySmtpAddress ("{0}.{1}@contoso.com" -f $_.firstname,$_.lastname) -EmailAddressPolicyEnabled $false }

CSV file format:


Alias,Firstname,Lastname
Test.cloud,Test,Cloud




Provide Full Access Permission on multiple User Mailboxes for any Admin Account:

Note: Paste the below command into TXT file and change the file extension into .PS1 and run the .PS1 file into Exchange Management Console.

-
$csv = import-csv "C:\Powershell\user.csv"
$csv | Foreach {
$Indentity = $_.ID
Add-MailboxPermission -Identity $_.ID -User TestAdmin -AccessRights FullAccess
}

CSV File format:

Id
Test.Cloud



Delete Bulk Exchange Public Folders:

Note: Paste the below command into TXT file and change the file extension into .PS1 and run the .PS1 file into Exchange Management Console.

-
$csv = import-csv "C:\Powershell\Delete_BulkPublicFolder\Public.csv"
$csv | Foreach {
Remove-PublicFolder -id $_.id -confirm:$false
}


CSV file format:


id
\Test4
\Test5
\Test6


Extract Exchange 2007 Active sync users list:

Get-Mailbox -ResultSize:Unlimited | ForEach {Get-ActiveSyncDeviceStatistics -Mailbox:$_.Identity} |ft identity,devicemodel,devicetype,LastSuccessSync >c:\user.csv


To get Exchange 2007 CAS server Certificate details:

Get-ExchangeCertificate | select thumbprint, issuer, isselfsigned, services, notafter


Remove Certificate:

Remove-ExchangeCertificate -Thumbprint 15de8243s72gchb75h4d8108626674333d013f


ActiveSync policy applies to Bulk Users:

Import-CSV -Path C:\Powershell\iphonepolicy.csv | % {Set-CASMailbox -Identity $_.Alias -ActiveSyncMailboxPolicy (Get-ActiveSyncMailboxPolicy “iPhone Test policy”)}

CSV File Format:
Alias
Test.cloud
Test.active


To Create Bulk External Contacts:

Note: Paste the below command into TXT file and change the file extension into .PS1 and run the .PS1 file into Exchange Management Console.

$csv = import-csv D:\Powershell\Conatcts\Createcontacts3.csv
$csv | % {
new-mailcontact -name $_.name -Firstname $_.firstname -lastname $_.lastname -alias $_.alias -externalemailaddress $_.external -OrganizationalUnit $_.OUpath
Set-MailContact $name -HiddenFromAddressLists $Enabled
}


CSV File format:
name,firstname,lastname,alias,external,Oupath
Test Cloud,Test,Cloud,Test.Cloud,test.cloud@gmail.com, OU=Test,OU=Conatcts,DC=Contoso,DC=com"


To Set multiple DOMAIN CONTRL in Exchange Server:

Set-ExchangeServer -identity Exch01-DomainController dc01.domain.com -StaticDomainControllers ‘dc01.domain.com’,‘dc02.domain.com’ -StaticGlobalCatalogs ‘dc01.domain.com’, dc02.domain.com’-StaticConfigDomainController ‘dc01.domain.com’, ‘dc02.domain.com’




To find Manual quota is defined or not for Bulk users:
Open a .txt file and copy the below command, save the file as .ps1
-------------------------------------------------------------
$CSV = Import-Csv "C:\Powershell\quota.csv"
$csv  | Foreach {
$Indentity = $_.Alias
get-mailbox -Identity $_.Alias | Where {$_.UseDatabaseQuotaDefaults -eq $false}
}
------------------------------------------------------------

CSV Format:
Alias
Test.user
Test.user1

Get Database Quota Result for all Mailbox servers:

Get-MailboxDatabase | Select-Object ServerName,Name,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota | Sort-Object Name | Export-Csv :\DatabaseLimits.csv –NoTypeInformation


Apply Quota for Bulk Database:

Copy below to TXT file and convert into .PS1
------------------------------------
$csv = import-csv "C:\Powershell\DB\DB.csv"
$csv | Foreach {
Set-MailboxDatabase-Identity $_.DB -IssueWarningQuota 900MB -ProhibitSendQuota 1024MB -ProhibitSendReceiveQuota 8192MB
}
-----------------------------------

CSV Format:
DB
MAIL1\SG1\MBXStore1
MAIL1\SG2\MBXStore2
MAIL1\SG3\MBXStore3

 
ActiveSync policy user list with Policyname and server
Get-CASMailbox -Filter {ActiveSyncMailboxPolicy -eq $ActiveSyncPolicyName} |ft Displayname, ActiveSyncMailboxPolicy, Servername
 
Search by ActiveSync Policy Name
Get-CASMailbox -ResultSize 20000000 | where{$_.activesyncmailboxpolicy -match "ActiveSync Without Device Password Policy"} | ft Displayname >d:\result.csv


Hope this helps.
Expect more!!



User Mailbox Statistics report from Exchange Server


Oh PowerShell How I love you!!, Believe me, the below single command line can get the User Mailbox Statistics report from exchange servers.


User Mailbox Statistics report Storage Wise from Exchange Management Shell


Get-MailboxStatistics -server <exchange server Name> | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},storagegroupname,servername> c:\result.txt
 

User Mailbox Statistics report OU base from exchange Shell

Get-Mailbox –OrganizationalUnit "contoso.com/Users/Students" | Get-MailboxStatistics | Sort-Object TotalItemSize-Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},storagegroupname,servername >c:\result.txt




PowerShell just rocks, isn't it!!!!

Exchange Database Size Reports

Continuing with our messaging “how tos”, the below exchange POWERSHELL script will help you to get Exchange Database Report:


Database Size Reports


$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }


foreach ($server in $exchangeservers)

{

$db = Get-MailboxDatabase -server $server

foreach ($objItem in $db)

{

$edbfilepath = $objItem.edbfilepath

$path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)

$dbsize = Get-ChildItem $path

$dbpath = $EdbFilePath.PathName.Remove(0,2).Replace(".edb","")

$ReturnedObj = New-Object PSObject

$ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity

$ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))

Write-Output $ReturnedObj

}

}



Note: Just copy past should work. I wish and hope it would!

Script to get User Mailbox Quota Report

We messaging Admins come across situations where we have to extract user’s mailbox quota report, below command line scripts help you to get the details in different scenarios:

To get the Quota Define List:

Get-Mailbox  -ResultSize 20000000 | Where {$_.UseDatabaseQuotaDefaults -eq $false} |Select Name,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota >c:\Quota_user.txt

From Any OU:

Get-Mailbox –OrganizationalUnit  "contoso.com/Users/Staff" -ResultSize 20000000 | Where {$_.UseDatabaseQuotaDefaults -eq $true} |Select Name,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota >c:\Quota_user.txt



Hope this helps.

Expect more !!