Hi Rob,
One way of doing it, would be to add a where-object statement when it searches AD.
Depending on which version of Powershell you are using, you can add the below commands to add a parameter and a where-object statement:
PS1.0Param([string]$ComputerName)
...
$StrExchangeServers | Where-Object {$_.path -match $ComputerName} | Foreach-Object `
...
PS2.0: [cmdletbinding()]
Param
(
[parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[String[]]
$ComputerName
)
...
$StrExchangeServers | Where-Object {$_.path -match $ComputerName} | Foreach-Object `
...
V1
<br>Function iCheck-GetExchangeRAWDBSizes
{
Param([string]$ComputerName)
#Get Exchange StorageGroup info from AD
$objRootDSE = [ADSI]"LDAP://rootDSE"
$strConfigurationNC = $objRootDSE.configurationNamingContext
$objConfigurationNC = New-object System.DirectoryServices.DirectoryEntry("LDAP://$strConfigurationNC")
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objConfigurationNC
$objSearcher.PageSize = 1000
$objSearcher.Filter = "(objectCategory=msExchStorageGroup)"
$objSearcher.SearchScope = "Subtree"
$StrExchangeServers = $objSearcher.FindAll() | Sort-Object Path
#Foreach Exchange server, extract private & public mailbox data info from AD and use get-item to extract file sizes
$StrExchangeServers | Where-Object {$_.path -match $ComputerName} | Foreach-Object `
{
...<br> V2
<br>Function iCheck-GetExchangeRAWDBSizes
{
[cmdletbinding()]
Param
(
[parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[String[]]
$ComputerName
)
#Get Exchange StorageGroup info from AD
$objRootDSE = [ADSI]"LDAP://rootDSE"
$strConfigurationNC = $objRootDSE.configurationNamingContext
$objConfigurationNC = New-object System.DirectoryServices.DirectoryEntry("LDAP://$strConfigurationNC")
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objConfigurationNC
$objSearcher.PageSize = 1000
$objSearcher.Filter = "(objectCategory=msExchStorageGroup)"
$objSearcher.SearchScope = "Subtree"
$StrExchangeServers = $objSearcher.FindAll() | Sort-Object Path
#Foreach Exchange server, extract private & public mailbox data info from AD and use get-item to extract file sizes
$StrExchangeServers | Where-Object {$_.path -match $ComputerName} | Foreach-Object `
{
...
<br> To run the function for a single server use the following example:
> iCheck-GetExchangeRAWDBSizes ex01
To run for multiple servers, wrap it in a foreach-object:
> "Ex01","Ex02" | Foreach-Object {iCheck-GetExchangeRAWDBSizes $_}
Cheers
James