Tag Archives: Powershell

Powershell Execution Policy

Are you having trouble creating or running you Powershell scripts in Windows, remember that you need to adjust the default Powershell Execution Policy to allow the running of your scripts.

You may otherwise receive an error like the one below

File scriptexample.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details.

It’s very easy to adjust so don’t panic, just find your Powershell shortcut and remember to open it by “Right Clicking” and selecting “Run as administrator”

Next simply paste the line below into powershell, hit enter and then press “Y” and hit Enter one final time.

set-executionpolicy remotesigned

Microsoft Exchange 2007 and 2010 – Messages Queued For Delivery Powershell Script

I’ve been getting into Powershell in a big way the past few months and have put together a script to display the number of queued messages on a Microsoft Exchange 2007 or Microsoft Exchange 2010 Server.  Under normal conditions your mail queue should really be empty most of the time so lots of queued messages is indicative of a problem.

 

$GETMQFD = Get-Counter ‘\MSExchangeTransport Queues(*)\Messages Queued For Delivery’

$MQFD = $GETMQFD.CounterSamples |Select-Object CookedValue

If ($MQFD.CookedValue | Where {$_ -eq 0})

{

Write-Host $MQFD.CookedValue Messages Queued for Delivery

}

Else

{

Write-Host “No Messages Queued For Delivery”

}

 

If you are using a Server Monitoring package such as GFI Max Remote Management then you can insert Exit Codes (i.e. Exit 1 or Exit 0).  This is placed after the output (i.e. Write-Host “No Messages Queued For Delivery”) to generate an onscreen error or success if one of the two conditions is met.

How to install Powershell ISE

Do you want to design, develop and test powershell scripts on your Windows Server?

If you are running Microsoft Windows Server 2008 R2 or Microsoft Windows Small Business Server 2011 then you will not be able to “right click” and select “Edit” you can however choose to run the script.

You need the Powershell Integrated Scripting Environment to be able to easily create, edit and debug your powershell scripts.

To install it just open Powershell, usually it is best to do this by “right clicking” your Powershell shortcut and clicking “Run as administrator”.  Once Powershell is open simply paste in the following text and then click “Enter” to start the install process

 

Import-Module ServerManager;Add-WindowsFeature PowerShell-ISE

 

You should now see “Powershell ISE” under Start Menu, Accessories and Windows Powershell.