Archive for category PowerShell

PowerShell Variables and scopes

I was helping someone with a profile script. The script is supposed to connect to a remote Exchange 2010 server using PowerShell v2.0 when it is launched.

The script had a function which is called upon when profile is loaded. The function looked like the following:

function connect-remotely()
 
{
      if ($server)
      {
            $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$server/PowerShell/ -Authentication Kerberos
            Import-PSSession $Session
            write-warning 'Do not forget to run Remove-PSSession $Session'
      }
      else
      {
            $server = read-host "Server name"
            connect-remotely $server 
      }
}

The $session variable in this instance gets created and populated within the function. The problem, however, is not visible until a bit later. When we were done with our remote session, we tried to remove session using Remove-PSSession $session but encountered an error which indicated that $session has null value.

Why did that happen? That’s where I needed to understand how scopes work. The PowerShell session is created when we launch PowerShell. When the function is executed, a child scope is created. The $session variable is created within child scope. All is fine until after the function completes execution and exits. At this time, $session variable value becomes null since the scope in which it was created is no longer applicable.

But wait, don’t we need the object stored in that variable to remove session successfully? We sure do. So how do we address this?

This can be accomplished using one of the two ways:

1. Define the variable as global. This will make the variable available in all scopes including the one created by function and the parent scopes. Here’s how you can do it:

$Global:Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$server/PowerShell/ -Authentication Kerberos

2. Second option (I like it better) is to define scope. I used New-Variable as describe below when creating $session within function and scoping it to value of 1:

New-Variable -Name Session -Value (New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$server/PowerShell/ -Authentication Kerberos) -Scope 1

When you scope any variable, value 0 means the scope in which it was created. 1 means parent scope, 2 is grand parent and so on. By defining scope of 1, I made the variable available to parent scope of the function which is where I was running Remove-PSSession. As anyone can guess, both methods allowed me to successfully remove session as the variable $session stayed behind populated instead of becoming null.

Hopefully this will help you understand how scope can help in certain situations. For better understanding of scopes, head out to TechNet as it contains lot more information about scopes which is not in scope of this post… get it? ;)

  • Windows Live Favorites
  • Windows Live Spaces
  • TechNet
  • Twitter
  • LinkedIn
  • Technorati Favorites
  • Share/Bookmark
Print

Tags:

No Comments

How do I check Update Rollup version on Exchange 20xx Server?

Instead of updating my previous post which covers only Exchange 2007, I decided to create a new post which covers both versions.

Now that Update Rollup for Exchange Server 2010 is available, I have updated my previous script to check for Update Rollup versions on both Exchange Server 2007 and Exchange Server 2010. No need to have two versions of script. Just download this one!

Here’s what has changed between versions:

  • Product GUID has changed to AE1D439464EB1B8488741FFA028E291C (Exchange 2010) from 461C2B4266EDEF444B864AD6D9E5B613 (Exchange 2007).
  • Exchange writes installation information to HKLM\SOFTWARE\Microsoft\ExchangeServer\v14\Setup instead of “HKLM\SOFTWARE\Microsoft\Exchange\Setup”

The script below will do the work for you so you don’t need to remember what I just said above. Isn’t that what script is for?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Store header in variable
$headerLine = 
@"
 
Server Name,Rollup Update Description,Installed Date,ExSetup File Version
"@
 
# Write header to file
$headerLine | Out-File .\results.csv -Encoding ASCII -Append
 
function getRU()
{
# Set server to connect to
	$Server = "$_".ToUpper()
 
 
# Check if server is running Exchange 2007 or Exchange 2010
 
	$ExchVer = (Get-ExchangeServer $Server | ForEach {$_.AdminDisplayVersion.Major})
 
# Set appropriate base path to read Registry
# Exit function if server is not running Exchange 2007 or Exchange 2010
	if ($ExchVer -eq "8" -or $ExchVer -eq "14")
		{
			switch ($ExchVer)
			{
			 "14"	{
			 			$REG_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\AE1D439464EB1B8488741FFA028E291C\\Patches"
						$Reg_ExSetup = "SOFTWARE\\Microsoft\\ExchangeServer\\v14\\Setup"
			 		}
			 "8"	{
			 			$REG_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\461C2B4266EDEF444B864AD6D9E5B613\\Patches"
						$Reg_ExSetup = "SOFTWARE\\Microsoft\\Exchange\\Setup"
			 		}
			}
		} 
	else
		{return}
 
# Read Rollup Update information from servers
 
# Set Registry constants
	$VALUE1 = "DisplayName"
	$VALUE2 = "Installed"
	$VALUE3 = "MsiInstallPath"
 
# Open remote registry
	$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Server)
 
# Set regKey for MsiInstallPath
	$regKey= $reg.OpenSubKey($REG_ExSetup)
 
# Get Install Path from Registry and replace : with $
	$installPath = ($regkey.getvalue($VALUE3) | foreach {$_ -replace (":","`$")})
 
# Set ExSetup.exe path
	$binFile = "Bin\ExSetup.exe"
 
# Get ExSetup.exe file version
	$exSetupVer = ((Get-Command "\\$Server\$installPath$binFile").FileVersionInfo | ForEach {$_.FileVersion})
 
# Create an array of patch subkeys
	$regKey= $reg.OpenSubKey($REG_KEY).GetSubKeyNames() | ForEach {"$Reg_Key\\$_"}
 
# Walk through patch subkeys and store Rollup Update Description and Installed Date in array variables
	$dispName = [array] ($regkey | %{$reg.OpenSubKey($_).getvalue($VALUE1)})
	$instDate = [array] ($regkey | %{$reg.OpenSubKey($_).getvalue($VALUE2)})
 
# Loop Through array variables and output to a file
	$countmembers = 0
 
	if ($regkey -ne $null)
	{
		while ($countmembers -lt $dispName.Count)
		{
		$server+","+$dispName[$countmembers]+","+$instDate[$countmembers].substring(0,4)+"/"+$instDate[$countmembers].substring(4,2)+"/"+$instDate[$countmembers].substring(6,2)+","+$exsetupver | Out-File .\results.csv -Encoding ASCII -Append
		$countmembers++
		}
	}
	else
	{
		$server+",No Rollup Updates are installed,,"+$exsetupver | Out-File .\results.csv -Encoding ASCII -Append
	}
}
 
# Get Exchange 2007 servers and write Rollup Updates to results file
$Servers = (Get-ExchangeServer | Where-Object {($_.AdminDisplayVersion -match "8" -OR $_.AdminDisplayVersion -match "14") -AND $_.ServerRole -ne "ProvisionedServer" -and $_.ServerRole -ne "Edge"} | ForEach {$_.Name})
$Servers | ForEach {getRU}

Download – Get-ExchangeUpdateRollups.ps1

  • Windows Live Favorites
  • Windows Live Spaces
  • TechNet
  • Twitter
  • LinkedIn
  • Technorati Favorites
  • Share/Bookmark
Print

Tags:

3 Comments

Script to install Exchange 2010 pre-requisites for Windows Server 2008 R2

Even though installing pre-requisites on Windows Server 2008 R2 is simple and straight forward as described here, it makes it even faster if you were to use a script to do so.

MVP Anderson Patricio recently published a script for the same. What the script did not do is what I took liberty to add. I am publishing entire script below with credit to Anderson where it is due.

My code adds functionality to download and install Microsoft Filter Pack if the server has internet connectivity.

UPDATE: Pat Richard enhanced this script and added some checks and other functionality which makes it even more useful. You can read Pat’s post here. The script below is result of combined effort of Anderson, Pat and myself.

#############################################################################
# Set-Exchange2010Prereqs.ps1
# Configures the necessary prerequisites to install Exchange 2010 on a 
# Windows Server 2008 R2 server
#
# Pat Richard, MVP
# http://ucblogs.net/blogs/exchange
# 
# 1.0 – Original script 11/27/09 based on the work of Anderson Patricio and
# Bhargav Shukla 
# 
# Dedicated blog post:
# http://www.ucblogs.net/blogs/exchange/archive/2009/12/12/Automated-prerequisite-installation-via-PowerShell-for-Exchange-Server-2010-on-Windows-Server-2008-R2.aspx
#
# Some info taken from
# http://msmvps.com/blogs/andersonpatricio/archive/2009/11/13/installing-exchange-server-2010-pre-requisites-on-windows-server-2008-r2.aspx
# http://www.bhargavs.com/index.php/powershell/2009/11/script-to-install-exchange-2010-pre-requisites-for-windows-server-2008-r2/
#############################################################################
 
# Detect correct OS here and exit if no match
if (-not((Get-WMIObject win32_OperatingSystem).OSArchitecture -eq '64-bit') -and (Get-WMIObject win32_OperatingSystem).Version -eq '6.1.7600'){
	Write-Host "This script requires a 64bit version of Windows Server 2008 R2, which this is not." -ForegroundColor Red -BackgroundColor Black
	Exit
}
 
Function InstallFilterPack(){
# future: look and see if it's already installed
# 			via registry HKLM:\Software\Microsoft\CurrentVersion\Uninstall\{95120000-2000-0409-1000-0000000FF1CE}
	trap {
		Write-Host "Problem downloading FilterPackx64.exe. Please visit http://tinyurl.com/36yrlj"
		break
	}
	#set a var for the folder you are looking for
	$folderPath = 'C:\Temp'
 
	#Check if folder exists, if not, create it
	if (Test-Path $folderpath){
		Write-Host "The folder $folderPath exists."
	} else{
		Write-Host "The folder $folderPath does not exist, creating..." -NoNewline
		New-Item $folderpath -type directory | Out-Null
		Write-Host "done!" -ForegroundColor Green
	}
 
	# Check if file exists, if not, download it
	$file = $folderPath+"\FilterPackx64.exe"
	if (Test-Path $file){
		write-host "The file $file exists."
	} else {
		#Download Microsoft Filter Pack
		Write-Host "Downloading Microsoft Filter Pack..." -nonewline
		$clnt = New-Object System.Net.WebClient
		$url = "http://download.microsoft.com/download/b/e/6/be61cfa4-b59e-4f26-a641-5dbf906dee24/FilterPackx64.exe"
		$clnt.DownloadFile($url,$file)
		Write-Host "done!" -ForegroundColor Green
	} 
	#Install Microsoft Filter Pack
	Write-Host "Installing Microsoft Filter Pack..." -nonewline
	$expression = $folderPath+"\FilterPackx64.exe /quiet /norestart"
	Invoke-Expression $expression
	Start-Sleep -Seconds 10
	write-host "done!" -ForegroundColor Green	
}
 
Function SetRunOnce(){
	# Sets the NetTCPPortSharing service for automatic startup before the first reboot
	# by using the old RunOnce registry key (because the service doesn't yet exist, or we could
	# use 'Set-Service')
	$hostname = hostname
	$RunOnceCommand = "sc \\$hostname config NetTcpPortSharing start= auto"
	if (Get-ItemProperty -Name "NetTCPPortSharing" -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce' -ErrorAction SilentlyContinue) { 
	    	Write-host "Registry key HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce\NetTCPPortSharing already exists." -ForegroundColor yellow
        	Set-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "NetTCPPortSharing" -Value $RunOnceCommand | Out-Null
	} else { 
	    	New-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "NetTCPPortSharing" -Value $RunOnceCommand -PropertyType "String" | Out-Null
	} 
}
 
Import-Module ServerManager
$opt = "None"
# Do { 
	clear
	if ($opt -ne "None") {write-host "Last command: "$opt -foregroundcolor Yellow}
	write-host
	write-host Exchange Server 2010 - Prerequisites script
	write-host Please, select which role you are going to install..
	write-host
	write-host '1) Hub Transport'
	write-host '2) Client Access Server'
	write-host '3) Mailbox'
	write-host '4) Unified Messaging'
	write-host '5) Edge Transport'
	write-host '6) Typical (CAS/HUB/Mailbox)'
	write-host '7) Client Access and Hub Transport'
	write-host
	write-host '9) Configure NetTCP Port Sharing service'
	write-host '   Required for the Client Access Server role' -foregroundcolor yellow
	write-host '   Automatically set for options 2,6, and 7' -foregroundcolor yellow
	write-host '10) Install 2007 Office System Converter: Microsoft Filter Pack'
	write-host '    Required if installing Hub Transport or Mailbox Server roles' -foregroundcolor yellow
	write-host '    Automatically set for options 1, 3, 6, and 7' -foregroundcolor yellow
	write-host 
	write-host '13) Restart the Server'
	write-host '14) End'
	write-host
	$opt = Read-Host "Select an option.. [1-14]? "
 
	switch ($opt)    {
		1 { InstallFilterPack; Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server -restart }
		2 { SetRunOnce; Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy -restart }
		3 { InstallFilterPack; Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server -restart }
		4 { Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Desktop-Experience -restart }
		5 { Add-WindowsFeature NET-Framework,RSAT-ADDS,ADLDS -restart }
		6 { SetRunOnce; InstallFilterPack; Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy -restart }
		7 { SetRunOnce; InstallFilterPack; Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy -restart }
		9 { Set-Service NetTcpPortSharing -StartupType Automatic }
		10 {
			# future - auto detect Internet access
			write-host 'Can this server access the Internet?'
			$filtpack = read-host 'Please type (Y)es or (N)o...'
			switch ($filtpack)				{
				Y {InstallFilterPack}
				N {Write-warning 'Please download and install Microsoft Filter Pack from here: http://tinyurl.com/36yrlj'}
			}
		}
		13 { Restart-Computer }
		14 {write-host "Exiting..."}
		default {write-host "You haven't selected any of the available options. "}
	}
# }
# while ($opt -ne 14)
  • Windows Live Favorites
  • Windows Live Spaces
  • TechNet
  • Twitter
  • LinkedIn
  • Technorati Favorites
  • Share/Bookmark
Print

Tags: , ,

6 Comments

How to bypass confirmation prompts for Managed Folder Policy

When you try to apply managed mailbox folder policy to a mailbox using set-mailbox, you would run a command like this:

 

set-mailbox -identity mailboxA -ManagedFolderMailboxPolicy "MFPolicy"

 

This would result in a confirmation prompt

 

Confirm 
  <br />Are you sure you want to perform this action?
  <br />...

 

To avoid the prompt, you instead run command

 

set-mailbox -identity mailboxA -ManagedFolderMailboxPolicy "MFPolicy" –confirm:$false

 

However, you will get prompted again with the following:

 

Confirm 
  <br />When assigning a managed folder mailbox policy…

To put it in perspective, the first confirmation prompt is for set-mailbox operation. The second confirmation prompt is for applying Managed Folder Policy. Whenever Managed Folder Policy is applied, it impacts legacy Outlook client functionality. Which explains why additional confirmation is needed.

So, how can you tell the shell not to ask you for confirmation as you know what you are doing or you don’t care if it breaks ;) ?

Type this:

set-mailbox -identity mailboxA -ManagedFolderMailboxPolicy "MFPolicy" -ManagedFolderMailboxPolicyAllowed -Confirm:$false

you can now tell the computer who is the boss. :)

  • Windows Live Favorites
  • Windows Live Spaces
  • TechNet
  • Twitter
  • LinkedIn
  • Technorati Favorites
  • Share/Bookmark
Print

Tags: ,

No Comments

Exchange 2007 PowerShell Scripts – What would you like to script?

I am always thinking about how can I script/automate tasks I have to do repeatedly or I see others ask for. I would like to go a step beyond. I would like to ask you – the readers:

If you would want to script something for your Exchange 2007 environment, what would it be?

I am going to keep comments open on this one so please comment and provide me the list you would like to see scripts on. You can also use contact form if you like.

  • Windows Live Favorites
  • Windows Live Spaces
  • TechNet
  • Twitter
  • LinkedIn
  • Technorati Favorites
  • Share/Bookmark
Print

Tags:

No Comments

Get-Service StartupType

If you want to find out startup type of a service using Get-Service cmdlet, you are out of luck. Get-Service cmdlet does not have StartupType property. Set-Service however does. So how can you find out the startup type of a service using powershell?

You can use Get-WmiObject.

(Get-WmiObject Win32_Service -filter "Name='W32Time'").StartMode

Once you determine the startup type of desired service, you can change it using Set-Service cmdlet:

Set-Service W32Time - StartupType Manual
  • Windows Live Favorites
  • Windows Live Spaces
  • TechNet
  • Twitter
  • LinkedIn
  • Technorati Favorites
  • Share/Bookmark
Print

Tags:

No Comments

Measure script run time

When I am writing PowerShell scripts, one thing that is always in my mind: How long will it take to run this script and what can I do to reduce the run time.

While optimizing the code itself is not the scope of this article, what I am going to write may help you determine how long your script, function or code sections takes to run.

Insert the following at start of the section of code you want to check:

# Get Start Time
$startDTM = (Get-Date)

Insert the following at the end of the section of code you want to check:

# Get End Time
$endDTM = (Get-Date)
 
# Echo Time elapsed
"Elapsed Time: $(($endDTM-$startDTM).totalseconds) seconds"

Here is an example of my code optimization:

BEFORE (Run Time 40.4 seconds):

filter GetMailboxCount{
$Server = $_
 
$strFilter = "(&(&(& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(msExchHomeServerName=$Server)) ))))"
 
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
 
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
 
$colResults = $objSearcher.FindAll()
$colCount = ($colResults | Measure-Object | %{$_.Count})
"$Server,$colCount"
 
}

AFTER (Run Time 4.53 seconds):

filter GetMailboxCount{
$Server = $_
 
$strFilter = "(&(&(& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(msExchHomeServerName=$Server)) ))))"
 
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
 
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
 
$colProplist = "name"
$retval = $colProplist | foreach {$objSearcher.PropertiesToLoad.Add($_)}
 
$colResults = $objSearcher.FindAll()
$colCount = ($colResults | Measure-Object | %{$_.Count})
"$Server,$colCount"
 
}

As you will see the “name” property is irrelevant to my code but by querying on indexed attribute and limiting scope of the query, I was able to improve run time ten folds. Now that is huge time savings when you have to run this code in a loop across all of your servers!

  • Windows Live Favorites
  • Windows Live Spaces
  • TechNet
  • Twitter
  • LinkedIn
  • Technorati Favorites
  • Share/Bookmark
Print

Tags:

No Comments

How do I check Rollup Update version on Exchange 2007 server?

This is one question that gets asked around many times! The article “Exchange Server 2007: Platforms, Editions and Versions” gives important information to identify the build numbers for each Rollup Updates, however, it is unclear where to look for this information.

To solve that problem, I have come up with a script which looks at Exsetup.exe version and registry entries for each Rollup Update installed…

Uh, what happened to the rest of this post?

Well, since I wrote a better script that handles both Exchange 2010 and Exchange 2007, I have removed this script. You can find new version here.

  • Windows Live Favorites
  • Windows Live Spaces
  • TechNet
  • Twitter
  • LinkedIn
  • Technorati Favorites
  • Share/Bookmark
Print

Tags: ,

No Comments

Corrupt or Missing Performance Counters

One of the functions in the code I posted in “Check Exchange 2003 vitals with PowerShell” is to check performance counters. When running the script, you may encounter an error:

Get-WmiObject : Invalid Class

 

This could happen for 2 reasons:

1: You have a typo in Perf Counter object.

2: The performance counter is missing on the host you are checking.

 

When this happened to me, I checked and verified this by loading performance monitor on affected server and trying to load Memory counters which the code was checking for. To no surprise, I found that the server did not have Memory object.

There are many reasons why the performance object could go missing from the OS. The KB article “How to manually rebuild Performance Counter Library values” explains how you can resolve this problem and bring the missing performance counter objects back.

  • Windows Live Favorites
  • Windows Live Spaces
  • TechNet
  • Twitter
  • LinkedIn
  • Technorati Favorites
  • Share/Bookmark
Print

Tags: , ,

No Comments

Check Exchange 2003 vitals with PowerShell – Part II

In continuation to my previous post “Check Exchange 2003 vitals with PowerShell”, I also have a code block that you can replace if you want to query all exchange servers in your environment dynamically with script instead of using text file as in the code I posted earlier.

In the code I posted earlier, the following lines read the file servers.txt.

1
2
3
# Read file and store server names in variable
 
$Servers = (Get-Content .\servers.txt)

Replace it with the following, which queries Active Directory for objectclass msExchExchangeServer and returns all servers found.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Get Exchange Servers from Active Directory
 
function GetExchangeServers()
{
	# Set variables to connect to Active Directory, searching Configuration Naming Context
	$root= New-Object System.DirectoryServices.DirectoryEntry("LDAP://RootDSE")
	$configpartition = [adsi]("LDAP://CN=Microsoft Exchange,CN=Services," + $root.configurationNamingContext)
 
	# Set variables for search criteria
	$search = New-Object System.DirectoryServices.DirectorySearcher($configpartition)
	$search.filter = '(objectclass=msExchExchangeServer)'  
 
	# Perform Serach, this will return all Exchange Server objects
	$ExchServer = $search.FindAll()
 
	# Output Name property of each server object stored in ExchServer array
	$ExchServer | foreach {$_.properties.name}
 
	# Comment the line above and uncomment the line below if you want to search specific Exchange servers by name
	# The example filter below will only output servers that have MBX in their name (i.e. MBX01, SRVMBX45 etc.)
	#$ExchServer | foreach {$_.properties.legacyexchangedn -match "MBX"}
}

You will also have to replace the lines:

1
2
# Get vitals for each server stored in $Servers array
$Servers | %{getVitals}

with the following:

1
2
# Get vitals for each server stored in $Servers array
GetExchangeServers | %{getVitals}


Comments welcome.

  • Windows Live Favorites
  • Windows Live Spaces
  • TechNet
  • Twitter
  • LinkedIn
  • Technorati Favorites
  • Share/Bookmark
Print

Tags: ,

No Comments