Ping with PowerShell

If you want to ping a device trough PowerShell then you can use the script below:

-Pouyan

The WinRM client received an HTTP server error status (502)

If you get the following error when you try to connect to your WinRM client, try the command below:

Try the command below:

Deleting and re-adding computers in WSUS

Have you deleted PC from WSUS with remove from WSUS option and you can’t add it back to WSUS? Well try the steps below to fix this problem:

Get number of mailboxes in each database?

Many times we need to find number of mailboxes in each database and the size of the database (EDB file) of all servers in an Exchange 2010 environment. With PowerShell, it is fairly simple to grab in a single line.

Export to CSV:

PowerShell – Delete old IIS logs

Just a quick script that may come in useful to you. The below PowerShell script will delete IIS Log files older than 7 days that are in the “C:\inetpub\logs\LogFiles\w3svc1” directory. You can alter the script to how many days old the log files can be and also your IIS log location.

-Pouyan

PowerShell – Search the Public Folder

If you want search in the public folder database for an folder you can use the scripts below.

If you know the exact name of the folder:

If you don’t know the exact name:

-Pouyan

How to Delete the First Database and Move the System Mailboxes

When you try to delete the Default Mailbox Database(created with 1st installation of the Mailbox Role), you receive the error below:

“This mailbox database contains one or more mailboxes or arbitration mailboxes. Before you can remove this mailbox database, you must disable, move or remove user mailboxes and move arbitration mailboxes.”

The First database contains the SystemMailboxes which are the Arbitration mailbox(es).

We have to move these system mailboxes to another database before of remove the Default Database.

1. Find the Arbitration Mailbox using the Exchange MAnagement Shell (EMS):

2. Now create a new move request in order to move the system mailboxes to another mailbox database:

3. Verify whether the move request completed:

4. Now remove the move request

PowerShell – Disconnected mailboxes are not yet marked as disconnected

Use the Clean-MailboxDatabase cmdlet to scan the Active Directory directory service for disconnected mailboxes that are not yet marked as disconnected in the Microsoft Exchange store and update the status of those mailboxes in the Exchange store.
This cmdlet is not able to update the Exchange store unless the Microsoft Exchange Information Store service is running and the database is mounted.

Run from exchange management shell:

From remote or normal Powershell window:

-Pouyan

PowerShell – Check if email address exists

You can use -ANR to search using Ambiguous Name Resolution (so you can type their first, last, username, etc), but while ANR will match a user’s primary email address, it will not match their other SMTP aliases. ANR can return multiple matches (so ensure your code handles this case).

For email address:

For public folder email address:

– Pouyan

PowerShell – Environment variables

When working with PowerShell I’m searching for the same variables over and over again. Every time when I found them again I think the same “Oh yeah, I knew that!”. To minimize my search next time I thought about writing it down.

First question, how do I use these variables? This is pretty straightforward.

Second question, which environment variables can I use? Use the following cmdlet: