Tuesday, 23 September 2008

Get-Scripting Podcast Episode 2 - (If you don't learn Powershell, tomorrow you'll be serving fries in McDonalds)

Welcome to Episode 2 of the Get-Scripting podcast! Tune in to listen to us talk and interview people about Powershell.

Download it here, subscribe in iTunes or via a different feed reader.

In this episode we have an interview with Thorbjörn Sjövold CTO of Special Operations Software.

Blog note links:

Ways to learn Powershell:

Windows Powershell Cookbook - Lee Holmes.

Powerscripting Podcast - Check out their back catalogue if you are new to Powershell, there is a lot of great content for you. Recent interviews include Jeffery Snover, Jeffery Hicks......upcoming is an interview with Don Jones and Greg Shields.


Interview

Special Operations Software

New version of Gpupdate based on Powershell

Specops Command - Powershell remoting through Group Policy

Other Specops products we talked about


Scandinavian Powershell Usergroup


Favourite cmdlets

Get-Date


Eureka Scripts

Jon Noble - Setting AD logon hours in Powershell, or "How to disable an AD user account and still allow delivery to the Exchange mailbox"

Dmitry Sotnikov - Setting Demo AD environments


Favourite Cmdlets

Send us what your favourite cmdlet is and why, and we'll enter you into the prize draw for Specops USB Pens and Mug.

get [dash] scripting [at] hotmail [dot] co [dot] uk


Feedback

Send us feedback at

get [dash] scripting [at] hotmail [dot] co [dot] uk

or leave a comment here on the blog


Wednesday, 10 September 2008

Exchange 2003, WMI, AD and Powershell - Part 5 (Querying AD for Exchange 2003 Information)

In previous posts in this series we have looked in particular at some of the Exchange 2003 WMI classes. So far this has required manual specification of which Exchange server you want to retrieve info from; wouldn't it be nice if you could use Powershell to find all the Exchange 2003 servers in your environment then run the WMI query against the results? Fortunately for us Exchange 2003 stores a lot of configuration information in Active Directory so we can query AD to retrieve what we need. There is a great article here which details how you can do this. We do the following:

Create a new directory object using .Net for the current AD domain.

$root= New-Object System.DirectoryServices.DirectoryEntry("LDAP://RootDSE")

Use ADSI to get the configuration partition of AD.

$cfgNC = [adsi]("LDAP://" + $root.Get("configurationNamingContext"))

Create a directory search object

$search = New-Object System.DirectoryServices.DirectorySearcher($cfgNC)

Filter on the Exchange Server object class - the below image should help illustrate what we are doing here. (other classes you can search on can be found here)

$search.filter = '(objectclass=msExchExchangeServer)'






Use the FindAll method to execute the search.

$ExchServer = $search.FindAll()

Finally, return the names of all the results.

$ExchServer | foreach {$_.properties.name}

Which in the example from the screenshot would produce a result:

EXCH

You can now combine this with any of the previous WMI scripts to run them against all the Exchange servers in your environment, e.g. for Top 10 largest mailboxes on each server:

$root= New-Object System.DirectoryServices.DirectoryEntry("LDAP://RootDSE")
$cfgNC = [adsi]("LDAP://" + $root.Get("configurationNamingContext"))
$search = New-Object System.DirectoryServices.DirectorySearcher($cfgNC)
$search.filter = '(objectclass=msExchExchangeServer)'
$ExchServer = $search.FindAll()

foreach ($server in $ExchServer)
{
$ExchangeServers = $ExchangeServers + $ExchServer | foreach {$_.properties.name}
}
foreach ($computer in $ExchangeServers) {
Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer $computer | sort-object Size -Descending | select-object -First 10 MailboxDisplayName,Servername,StorageGroupName,StoreName,Size}

Wednesday, 3 September 2008

IKEA, Bjorn Borg, Henrik Larsson, Powershell.........the Get-Scripting Podcast heads to Sweden.

In the interests of audio quality (ok so they have invited me over and are funding the trip) I'll be interviewing the great guys at Special Operations Software in person in Stockholm for Episode 2 of the podcast. If there's anything you always wanted to ask them then let me know.

Coinciding with the visit they are helping to run a Powershell event at Microsoft in Sweden. This will be a great event to attend if you are in the area and / or able to make it there since Richard Siddaway from the UK Powershell user group will be presenting the event.

In case you can't speak Swedish, in the morning is an official Technet event (sign up here) and in the afternoon is the inaugural meeting of the Swedish / Nordic Powershell usergroup.

Update 10/09/08: the Scandanavian Powershell Usergroup now has a website!

Since I'll be in town for the interview I'll be tagging along to the event, hopefully I might bump into some of the listeners to the podcast there - if you are going please say hello if you see me. I'll be the other English guy there who isn't at the front of the room. :-)

Wednesday, 27 August 2008

Get-Scripting Podcast Episode 1

Welcome to Episode 1 of the Get-Scripting podcast! Tune in to listen to us talk and interview people about Powershell.

Download it here , subscribe in iTunes or via a different feed reader.

In this epsiode we have part 2 of an interview with James O'Neill from Microsoft - we talk about Cmdlets v Providers, V2 CTP and the Powershell Community.

Blog note links:

Ways to learn Powershell:


Powershell Step by Step - Ed Wilson is available as a free eBook. (Look on the Special Offers tab)


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


Update 29/08: A helpful listener Brad Bruce has pointed out the above link no longer has the ebook available. I checked it out and he is correct. :-( It was there last week when I prepared the show and has been for around the last year, unfortunately I never got round to downloading it myself - if anyone has it can they please get in contact and I can then pass it around to anyone who wants it.


Maybe they removed it because so many people tried to get it after listening to the podcast!


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


2008 Scripting Games

Interview

James O'Neill's blog

OCS Powerpack for Powergui. Authors blog


Eureka Scripts

Check Active Directory Latency - Brandon Shell

Exporting Virtual Infrastructure Information to MS Word - Alan Renouf


Selling Powershell to IS Management

Don Jones / Jeffrey Snover video


Powershell Event / Usergroup in Sweden

Sign up here

Richard's Blog post about it


Send us feedback at

get [dash] scripting [at] hotmail [dot] co [dot] uk

or leave a comment here on the blog

Tuesday, 26 August 2008

Exchange 2003, WMI and Powershell - Part 4.5 (Counting Users in Storage Groups and Mailbox Stores)

OK, so this wasn't going to be in the original series I was writing, but an issue came up at work where I needed to quickly find the total number of users in each Storage Group.

Naturally I turned to Powershell for the solution.

Just supply the names of the Storage Groups in a text file, use Powershell to open the text file and for each of the Storage Groups use the Exchange_Mailbox class and filter on the Storage Group name. Use the feature .count to just return the number of users rather than any properties and write to the screen the result.

$StorageGroups = Get-Content c:\Scripts\StorageGroups.txt
foreach ($SG in $StorageGroups){
$Total = (Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName -filter "StorageGroupName = '$SG'").count
Write-Host $SG ":" $Total "users"
}


Which produces something along the lines of:

Storage Group 01 : 152 users
Storage Group 02 : 373 users
Storage Group 03 : 259 users
Storage Group 04 : 220 users


Taking this one step futher you can drill down into the Mailbox Stores with similar code (this time with the names of the Mailbox Stores in a text file) and find how many users on each store:

$MailboxStores = Get-Content c:\Scripts\MailboxStores.txt
foreach ($Store in $MailboxStores){
$Total = (Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName -filter "Storename = '$Store'").count
Write-Host $Store ":" $Total "users"
}

Which gives you the result:

Mailbox Store 01 : 23 users
Mailbox Store 02 : 32 users
Mailbox Store 03 : 41 users
Mailbox Store 04 : 30 users
Mailbox Store 05 : 26 users
Mailbox Store 06 : 39 users
etc.............

Friday, 8 August 2008

Exchange 2003, WMI and Powershell - Part 4 (Disconnected Mailboxes)

In parts 1 , 2 , 3 we looked at retrieving mailbox information from Exchange 2003 using WMI and Powershell.

In part 4 we're going to take another look at this topic area for something slightly more advanced - how to get a list of all mailboxes which have been deleted, but are still in the time frame for 'Keep Deleted Mailboxes for: x days'.

A typical scenario might be a mailbox has been deleted incorrectly and you need to re-connect it to an AD account; however, since the AD account has gone, how do you know which Mailbox Store was the home for the mailbox?

In the Exchange management GUI you would need to browse through each mailbox store looking for mailboxes marked with the red cross. Not too bad a job if you only have one mailbox store, but if that number is in the 10's of Mailbox Stores then its a pretty tedious task.

Step forward Powershell!

Again use the Exchange_Mailbox class and this time look for the DateDiscoveredAbsentInDS value. This value gets populated after the mailbox has been marked for deletion. We look for a value which begins with "2", i.e. the mailbox has been deleted sometime after the year 2000 (there may be a better way to do this), and return info about each mailbox in this state, including the Servername and Mailbox Store Name so that you can easily track the mailbox down.

Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName | where { $_.DateDiscoveredAbsentInDS -like '2*' } | sort-object MailboxDisplayName | ft MailboxDisplayName,ServerName,StorageGroupName,StoreName,Size,DateDiscoveredAbsentInDS


Update 12/08/08:

Thanks to Shay Levy who has come back with a better way to do this!

"Using a -filter parameter which makes your query run on the server and return only the relevant mailbox objects". You should find that this significantly improves the speed of the query. Check the comments for this post for full details.

Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName -filter "DateDiscoveredAbsentInDS is not null" | sort-object MailboxDisplayName | ft MailboxDisplayName,ServerName,StorageGroupName,StoreName,Size

Get-Scripting Podcast - how frequent?

A few people have asked "how often we are going to release new episodes of the podcast"?

We hope to record one every month, so all being well look for Episode 1 in the week beginning Monday 25th August.........