Prev | Current Page 128 | Next

Joezer Cookey-Gam, Brendan Keane, Jeffrey Rosen, and Jonathan Runyon

"Professional Windows PowerShell for Exchange Server 2007 Service Pack 1"

Most
organizations have a naming specification based on the role of the server. For example, mailbox servers
Chapter 3: Using PowerShell to Deploy Exchange Server 2007
73
are usually named MB or MBX , and CAS servers are usually CA or CAS . By using a unified naming
structure, PowerShell can read the system hostname and then make a decision on what roles to install
based on the server name. The following script presents the decision logic:
$server=[system.net.dns]::gethostname()
if ($server -like???*UM*???) {???$role=U???} else
{if ($server -like???*ES*???) {$role=???E???} else
{if ($server -like???*CA*???) {$role=???C???} else
{if ($server -like???*HT*???) {$role=???H???} else
{if ($server -like???*MB*???) {$role=???M???} else
{if ($server -like???*EX*???) {$role=???M,H???} else
{Write-Host ???Server name does not match any known naming specification???}
}
}
}
}
}
This script starts by getting the server ??™ s hostname using a .NET call to request a DNS lookup on the
server. The response is assigned a variable of $server . From there an if else loop is constructed to run
using the like operator to search the $server variable for an expression. Based on the pattern that is
matched, it will either assign a value to the $role variable or it will write to the console that it was unable
to find a suitable match.


Pages:
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
Władysławowo wakacje tanie hotele w polsce skarpetki narciarskie męskie dobry katalog Życie