다음을 통해 공유


Using ServerManagerCmd

Longhorn is now officially Windows Server 2008. Beta 3 is now out and you can download the beta from the following URL: https://www.microsoft.com/windowsserver2008/default.mspx

 If you want to do the try before you buy take a look at the TechNet Virtual Labs for Windows Server 2008
https://www.microsoft.com/technet/traincert/virtuallab/longhorn.mspx

It does not matter how you plan to use Server 2008, you will need to manage it. This includes tasks such as adding or removing server roles or features. One way to do this is through Server Manager which is an expanded Microsoft Management Console (MMC). This is great if you want to us a UI to add and remove roles and features along with seeing what is available and what has already been installed.

If you don't want to use a UI you can take a look at the new ServerManagerCmd.exe. This is a new command-line tool that allows you to perform most of the Server Manager tasks outside of the Server Manager Console. This makes it a great tool to support scripting and automatic deployment of server roles or features.

Many times you want to find out what roles and features are installed. With ServerManagerCmd.exe you and issue the following command and get an xml file that lists all the different roles and features and if they are installed or not.

ServerManagerCmd.exe –query c:\myQuery.xml

If you look at the xml you will see something like the following:

<Role DisplayName="DHCP Server" Installed="false" Id="DHCP" />
<Role DisplayName="DNS Server" Installed="false" Id="DNS" />
<Feature DisplayName="BitLocker Drive Encryption" Installed="false" Id="BitLocker" />
<Feature DisplayName="Windows PowerShell" Installed="true" Id="PowerShell" />

If a Role or Feature has sub items they will also show, like the following:
<Role DisplayName="Active Directory Federation Services" Installed="false">
<RoleService DisplayName="Federation Service" Installed="false" Id="ADFS-Federation" /> <RoleService DisplayName="Federation Service Proxy" Installed="false" Id="ADFS-Proxy" />
<RoleService DisplayName="AD FS Web Agents" Installed="false" Id="ADFS-Web-Agents"> <RoleService DisplayName="Claims-aware Agent" Installed="false" Id="ADFS-Claims" />
<RoleService DisplayName="Windows Token-based Agent" Installed="false" Id="ADFS-Windows-Token" /> </RoleService>
</Role>

As you can see we list if the role or feature is installed and also give the Id which can be used to install or remove a role or feature. The results from the query allow you to quickly document what roles or features are currently installed on a specific server or compare two different servers.

Now let’s look at installing and removing a role or feature. By default PowerShell is not installed in the default server installation. So if you want to run PowerShell scripts you will need to install it. Here is the command that will install PowerShell:
ServerManagerCmd.exe –install PowerShell

This is fine if you don’t want to track what this does or see if installing PowerShell installs anything else. One nice feature of ServerManagerCmd.exe is the “whatIf” parameter. For example I want to check to see what installing PowerShell will do. So I run the following command.
ServerManagerCmd.exe –install PowerShell –whatIf –logPath c:\PSLog.txt

This creates a log file that shows what would have been done if the “whatIf” parameter was not there.

The “whatIf” parameter is a great way to check and see what a remove or install of a role or feature will do before you actually do it.

Ok now you are ready to install or remove a role or feature and you would like to document what actually happened. Don’t worry this can easily be done. Let’s look at the above command to install PowerShell again.
ServerManagerCmd.exe –install PowerShell –resultPath c:\PSInstall.xml –logPath –c:\PSInstallLog.txt

Now I get both and XML file that shows the results of my command and a log file to check if something went wrong. Here is what the XML for the –resultPath looks like:

<ServerManagerConfigurationResult Action="Install" Time="2007-07-03T16:32:31" Language="en-US" RequiresReboot="false" Success="true" xmlns="https://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1">

<Message Level="Information">Start Installation...</Message>

- <Feature DisplayName="Windows PowerShell" Id="PowerShell" RequestedBy="UserSpecified" Success="true" RequiresReboot="false">

<Message Level="Information">[Installation] Succeeded: [Windows PowerShell].</Message>

</Feature>

<Message Level="Information">Success: Installation succeeded.</Message>

</ServerManagerConfigurationResult>

We can see that this shows that the installation succeeded and that we don’t need to reboot the box (RequiresReboot="false") I now have documentation that provides information about what I changed along with date and time of the change. This is great if you need and audit trail.

The one area I am not covering in this article is how to use an XML answer file. This is a very powerful feature of ServerManagerCmd.exe. It allows you to create and XML file that contains information on how the install or remove of roles and features is done.

As we can see the ServerManagerCmd.exe provides a very powerful tool that allows for automation of installation and removal of roles and features in Windows Server 2008. For more information on Server Manager and ServerManagerCmd.exe see the following links:
https://technet2.microsoft.com/windowsserver2008/en/library/e7edce1d-442c-4ec3-b324-c748e4f937551033.mspx?mfr=true

https://technet2.microsoft.com/windowsserver2008/en/library/e7edce1d-442c-4ec3-b324-c748e4f937551033.mspx?mfr=true

https://technet2.microsoft.com/windowsserver2008/en/library/e7edce1d-442c-4ec3-b324-c748e4f937551033.mspx?mfr=true

Enjoy!

Brian

Comments