Posts

Exchange 2007 Powershell

Mailbox Size Report - Individual Database cls Get-MailboxStatistics -Database "ecgcmail01\webmail users\mailboxes" | Sort-Object TotalItemsize -Descending | Where {$_.TotalItemSize -gt 145MB} | ft Displayname , @{expression={$_.TotalItemSize.Value.ToMB()}}, StorageLimitStatus Get-MailboxStatistics -Database "ecgcmail01\general users\mailboxes" | Sort-Object TotalItemsize -Descending | Where {$_.TotalItemSize -gt 65MB} | ft Displayname , @{expression={$_.TotalItemSize.Value.ToMB()}}, StorageLimitStatus ******************************* update 10K Photo in AD Import-RecipientDataProperty -Identity "Bharat Suneja" -Picture -FileData ([Byte[]]$(Get-Content -Path "C:\pictures\BharatSuneja.jpg" -Encoding Byte -ReadCount 0)) ************************************** Enable OWA for list of users $path = “d:\Andy\Owa.txt” foreach ($line in Get-Content $path) { Set-CASMailbox –Identity $line –OWAEnabled:$true } ******************************

Some Exchange 2007 CMDlets

Mailbox Size Report - Individual Database cls Get-MailboxStatistics -Database "ecgcmail01\webmail users\mailboxes" | Sort-Object TotalItemsize -Descending | Where {$_.TotalItemSize -gt 145MB} | ft Displayname , @{expression={$_.TotalItemSize.Value.ToMB()}}, StorageLimitStatus Get-MailboxStatistics -Database "ecgcmail01\general users\mailboxes" | Sort-Object TotalItemsize -Descending | Where {$_.TotalItemSize -gt 65MB} | ft Displayname , @{expression={$_.TotalItemSize.Value.ToMB()}}, StorageLimitStatus ******************************* update 10K Photo in AD Import-RecipientDataProperty -Identity "Bharat Suneja" -Picture -FileData ([Byte[]]$(Get-Content -Path "C:\pictures\BharatSuneja.jpg" -Encoding Byte -ReadCount 0)) ************************************** Enable OWA for list of users $path = "d:\Andy\Owa.txt" foreach ($line in Get-Content $path) { Set-CASMailbox –Identity $line –OWAEnabled:$true } *******************

LDAP Queries

This LDAP query should show you all users in your enviroment with exchange mailboxes that have OWA enabled . (&(objectCategory= user )(!protocolsettings=HTTP*0*)(msExchUserAccountControl=0)) This LDAP query should show you all users in your enviroment with exchange mailboxes that have OWA disabled. (&(objectCategory= user )(protocolsettings=HTTP*0*)(msExchUserAccountControl=0))

Delete Media Files

Script to delete media files Script Code: ------------------------------------------------------------------------------ strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colFiles = objWMIService.ExecQuery _ ("Select * from CIM_DataFile where Extension = 'mp3' OR Extension = 'wma' OR Extension = 'flv' OR Extension = 'jpg' OR Extension = 'mov' OR Extension = 'avi' OR Extension = '3gp' OR Extension = 'flv' OR Extension = 'vob' OR Extension = 'mpeg'") For Each objFile in colFiles objFile.Delete Next

Cleanup Old Files

Script to Delete files older than X days Usage: cscript c:\scripts\deloldfiles.vbs c:\windows\system32\logfiles 30 >> c:\scripts\iis.log Scrpit Code: ----------------------------------------------------------------------------------------- ' Objective: To delete old files from a given folder and all subfolders below ' ' Created by: MAK June 21, 2005 ' ' Format: cscript deloldfiles.vbs {DriveLetter:\FolderName} {#ofDays} ' or: cscript deloldfiles.vbs {\\servername\FolderName} {#ofDays} ' Example: cscript deloldfiles.vbs c:\dba\log 3 ' (deletes files older than 3 days from the \dba\log file on drive C:) Set objArgs = WScript.Arguments FolderName =objArgs(0) Days=objArgs(1) set fso = createobject("scripting.filesystemobject") set folders = fso.getfolder(FolderName) datetoday = now() newdate = dateadd("d", Days*-1, datetoday) wscript.echo "Today:" & now() wscript.echo "Started deleting files older than :" &am

Batch command to change DNS

cd\ netsh int ip set dns "local area connection" static 10।120.135.100 primary 'Add primary DNS netsh int ip add dns "local area connection" 10.4.148.103 'Add secondary DNS netsh int ip add dns "local area connection" 10.120.135.101 'Add additional DNS

Script to remove domain user from local administrator group

' (This script can run as logon script without problems because it first check if the user is a member. ' If the user is a local administrator s/he has privileges to remove him/her self from the local group. ' Do Keep in mind however that the user at this stage already is logged-on as an Administrator, ' s/he will keep all the access rights until the next logon). Set objNetwork = CreateObject("Wscript.Network") strUser = objNetwork.UserName strDomain = objNetwork.UserDomain strComputer = objNetwork.ComputerName strLocalGroup = "Administrators" On Error Resume Next ' Bind to local group object. Set objGroup = GetObject("WinNT://" _ & strComputer & "/" & strLocalGroup & ",group") If (Err.Number <> 0) Then wscript.Quit ' Bind to the user object on the Domain. ' (use also the WinNT provider). Set objUser = GetObject("WinNT://" _ & strDomain & "/&qu