Sunday, October 2, 2011

My Exchange Powershells

Grant a user calender permission Exchange 2010
[PS] C:\>Add-MailboxFolderPermission amalik@elgendi.com:\Calendar -User skamel@elgendi.com -AccessRights editor


RunspaceId : 23325030-1dac-4fae-9c97-75380d4b7f2e
FolderName : Calendar
User : Sonia Kamel
AccessRights : {Editor}
Identity : SSonia Kamel Blablabla
IsValid : True


[PS] C:\>Add-MailboxFolderPermission amalik@elgendi.com:\Calendar -User pPoPs@elgendi.com -AccessRights editor


RunspaceId : 23325030-1dac-4fae-9c97-75380d4b7f2e
FolderName : Calendar
User : Paul PoPs
AccessRights : {Editor}
Identity : Paul Pops Blablabla
IsValid : True

------------------------------------------------------------------------------------------------------------

How to delete E-mail from all Mailboxes

In Exchange 2010 till Sp1

Get-Mailbox –Database ABC-3GB | Export-Mailbox -Identity asabry@elgendi.com –SubjectKeyWorks "Good Morning" –SenderKeyWorks "Ahmed Sabry" -DeleteContent


------------------------------------------------------------------------------------------------------------



Exchange 2010 powershell - get messages sent / received:

Get-MessageTrackingLog -recipient “123@domain.com” -eventID send -Start “05/01/2011 1:00AM” -End “06/23/2011 1:00am”
| Select timestamp,recipients,messagesubject




------------------------------------------------------------------------------------------------------------



In Exchange 2010 SP2
Search-Mailbox -Identity "Ahmed Sabry" -SearchQuery 'Subject:"Remove CMDLET"' -DeleteContent
I didnt like it as I can not specify the sender parameter, it deleted 5 messages , I was willing to delete only 1



 Message Tracking Results using Powershell

Get-MessageTrackingLog -Start "10/02/2011 00:00AM" -Sender "rajawi@ABC.com.it" > I:\test\rajawi2Oct.txt

------------------------------------------------------------------------------------------------------------

Get Exchange Database users Mailbox Size

Get-MailboxStatistics -Database K100MB | Sort-Object TotalItemSize -Descending | ft DisplayName,TotalItemSize,ItemCount > C:\Temp\Exchange\K100MB.txt


------------------------------------------------------------------------------------------------------------


Get Exchange DB & Log file locations:
Get-MailboxDatabase -Status | select ServerName,Name,DatabaseSize,EdbFilePath,LogFolderPath


------------------------------------------------------------------------------------------------------------


Quick checkup commands  :


test-replicationhealth
Get-MailboxDatabaseCopyStatus    :  ContentIndex State failed for “ABC-MB-01”
Test-ServiceHealth -Server  ABC-MB-02
Get-Queue -ServerABC-MB-02 | FL
Test-Mailflow ABC-MB-02 -TargetMailboxServer ABC-MB-01


------------------------------------------------------------------------------------------------------------

Export Mailbox command:

First grant the permission:

New-ManagementRoleAssignment -Role "Mailbox Import Export" -User aelgendi

Second export the Mailbox:
New-MailboxExportRequest -Mailbox "mquddus@abc.com.kw" -FilePath "\\10.7.1.42\OLpst\AbboITSMail.pst"

if you got an error you may need to clean the Database.

Get-Mailboxdatabase | Clean-MailboxDatabase

you can list disconnected by Databse:
Get-MailboxStatistics -Database ABC_DB | Where { $_.DisconnectReason -eq "SoftDeleted" -or $_.DisconnectReason -eq "Disabled" } | Format-List LegacyDN, DisplayName, MailboxGUID, DisconnectReason


=====================================================================
Get list of users by GB:
***
Get-MailboxStatistics -Server ABC-mb-01 | where {$_.ObjectClass –eq “Mailbox”} | Sort-Object TotalItemSize –

Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (GB)”;expression=

{$_.TotalItemSize.Value.ToGB()}},@{label=”Items”;expression={$_.ItemCount}},@{label=”Storage Limit”;expression=

{$_.StorageLimitStatus}} -auto > C:\PShellOutputs\sMailboxStatisticsREPORT.txt

Get list of users by MB:
***
Get-MailboxStatistics -Server ABC-mb-01 | where {$_.ObjectClass –eq “Mailbox”} | Sort-Object TotalItemSize –

Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression=

{$_.TotalItemSize.Value.ToMB()}},@{label=”Items”;expression={$_.ItemCount}},@{label=”Storage Limit”;expression=

{$_.StorageLimitStatus}} -auto > C:\PShellOutputs\sMailboxStatisticsREPORT.txt


If Mailbox is not appearing in disconnecrted mailbox:
Get-Mailboxdatabase | Clean-MailboxDatabase


****Determining Free Space in an Exchange 2010 Mailbox Database
Get-MailboxDatabase -Status | ft name,databasesize,availablenewmailboxspace -auto


** Top 20 Mailbox in Size:
Get-Mailbox -database "ABC_100MB" -ResultSize Unlimited| Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name="MailboxSize";exp={$_.totalitemsize}} -first 20 > c:\PShellOutputs\ABC_100MB.txt


Get-Mailbox -database "ABC_500MB" -ResultSize Unlimited| Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name="MailboxSize";exp={$_.totalitemsize}} -first 20 > c:\PShellOutputs\ABC_500MB.txt


Get-Mailbox -database "ABC_UNLIMITED" -ResultSize Unlimited| Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name="MailboxSize";exp={$_.totalitemsize}} -first 20 > c:\PShellOutputs\ABC_UNLIMITED.txt


Get-Mailbox -database "ABC_1GB" -ResultSize Unlimited| Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name="MailboxSize";exp={$_.totalitemsize}} -first 20 > c:\PShellOutputs\ABC_1GB.txt

==========================================================================

Migrating users to new Mailbox Database , Zero down time:

1. Assign two new drives to the active server one for DB and one for Log
2. Create a new database and point to the new drives
3. Change the Database logging level to ‘Circular logging’ on the new database
4. Move the users from KFH_1GB to the new database
5. After all the users are moved delete the old database
6. Remove the ‘circular logging’ from the new database
7. Reconfigure the drive letters on the passive node to match the new DB and log drives
8. Add the new database copy to the passive node


===========================================================
After NLB configuration you may need to run this command if the servers are not responding:
 netsh interface ipv4 set interface "NLB" forwarding=enabled

Sunday, September 25, 2011

Copy files over SFTP

Copy files over SFTP

using PSFTP: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html


psftp.exe 192.168..25.122 -P 22 -l UserName -pw Passw0rd -b C:\pathtoBatchFile.txt


pathtoBatchFile.txt:
==============
cd "/57/Inbound/DCMS Files"
mput DCMS*
ls
==============

Monday, September 19, 2011

The password stored in Credential Manager is invalid. This might be caused by the user changing the password from this computer or a different compute

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
and copy it to C:\Windows\System32 .
From a command prompt run: psexec -i -s -d cmd.exe
From the new DOS window run: rundll32 keymgr.dll,KRShowKeyMgr
Remove any items that appear in the list of Stored User Names and Passwords. Restart the computer.

Retrive user Member of which Active driectory groups

dsquery user "CN=Donya ,OU=Internal Audit,OU=123,DC=123,DC=bh,DC=com" -o dn | dsget user -memberof > c:\Temp\sep\Donya.txt

Thursday, September 15, 2011

How to Reset Local Group Policy Objects to default settings

I just copied it from a web site to keep it here as refrence

After much searching on how to do such a simple task as reset local GPOs back to their defaults, I finally found the real answer. I tried this on Windows XP, although it is said to work for 2000 and 2003 Server as well.

1. If you need to clear IPSec settings and software restriction settings do these two sub-steps, otherwise go on to the second step:
a. reg delete hklm\software\policies\microsoft /f
b. regedit /s "c:\policies.reg" (where c:\policies.reg is the exported hklm\software\policies\microsoft hive of a virgin or target configured machine)
2. Issue this magical command to reset the rest of the GPO settings to their defaults (enter this all on one line):
secedit /configure /db reset /cfg "c:\windows\security\templates\setup security.inf" /overwrite
3. Delete the registry.pol file if it exists:
del c:\windows\system32\grouppolicy\machine\registry.pol
4. Reboot

That's it! You're done!

Thursday, September 8, 2011

Wput Example

copy c:\ahmad\ftp\*.htm c:\ahmad\Backup\

wput c:\ahmad\Backup\*.htm ftp://ahmad:PaSsw0rd@127.0.0.1/

pause

Wednesday, August 24, 2011

Clean Up your active directory

1- Using Hyena software go to respective OU and retrieve a list of Computers
or
dsquery computer "OU=WSUS,DC=ABC,DC=KW,DC=com" -limit 1000 > C:\WsusComputers.txt
or if it was under container use:
dsquery computer "CN=Computers,DC=ABC,DC=KW,DC=com" -limit 1000 > C:\WsusComputers.txt


2- Clean them up by Excel to allow only Computer name and then save them to file.

3- Use:
C:\>for /f %a in (C:\lookup.txt) do nslookup %a | find /i "Address" >> c:\nslookup_results.txt
to resolve them to IPs



4- Use angry IP scanner to resolve them to DNS again but with IPs matched & FqDN.

5- Export to Excel and filter to remove [ns] [na] invalid IPs

6- Move them to separate OU:
dsquery computer -name muhq-teller2.ABC.bh.com | dsmove -newparent ou=muharraq,ou=computers,ou=ABC,dc=kfh,dc=bh,dc=com

7- get list of inactive computers for last 90 days:
dsquery computer -inactive 90 -limit 0

And move them as above as well.