Cross Platform PowerShell Scripts Released
We are happy to release several cross platform-specific PowerShell scripts to help automate the discovery of UNIX/Linux servers, installation and upgrade of the cross platform agents for Operations Manager 2007 R2, signing of the certificates, and changing the Management Server managing the UNIX/Linux server.
Four PowerShell scripts are currently available:
- ChangeUnixIsManagedBy.ps1
- DiscoverUnixAgent.ps1
- InstallUnixAgent.ps1
- UpgradeUnixAgent.ps1
Each of these scripts is covered in this article, and help for each of these scripts is available by running the script without any parameters.
These four scripts leverage several helper scripts, which do not perform any actions on their own (and return no output if run on their own):
- ChangeUnixIsManagedByImpl.ps1
- DiscoverUnixAgentImpl.ps1
- InstallUnixAgentImpl.ps1
- scx.ps1
- UpgradeUnixAgentImpl.ps1
The .zip file attached contains the files noted above.
Note: All of these scripts require PowerShell to be installed and are run from a Windows computer (not from a UNIX/Linux client computer).
ChangeUnixIsManagedBy.ps1
The ChangeUnixIsManagedBy script is used to change the current management server monitoring a UNIX/Linux server (or group of UNIX/Linux servers) to a new server as specified in the command line parameters.
The script accepts a list of Unix/Linux hosts on the input pipe. These hosts are represented either as strings with fully qualified domain names (FQDN) or as objects with a "ComputerName" string property with the FQDN.
The output of the script is a list of objects with a "ComputerName" string property with the FQDN of the Unix/Linux host and a "Status" property with the status of the operation for the current host.
The following parameters can be used with the ChangeUnixIsManagedBy script:
Parameter | Definition |
RootManagementServer | Name of OpsMgr root management server to use or empty string to use current computer (default) |
ManagementServer | Management Server to assign (required) |
Target | Additional computer to change management server for (done before any hosts are piped into script) |
Usage:
ChangeUnixIsManagedBy.ps1-RootManagmentServer: <RMS FQDN> -ManagementServer: <MS FQDN>
-Target: <Target Computer FQDN>
Examples:
You have a Linux computer named SLES10-1.contoso.com and you want to change its Management Server to ContosoMS2.contoso.com, so you would use the following command:
ChangeUnixIsManagedBy.ps1 -ManagementServer:ContosoMS2.contoso.com
-Target:SLES10-1.contoso.com
Note: The script can also be executed without the parameter names, but only if all the parameters are provided. For example:
ChangeUnixIsManagedBy.ps1 ContosoRMS.contoso.com ContosoMS2.contoso.com
SLES10-1.contoso.com
InstallUnixAgent.ps1
The InstallUnixAgent script is used to deploy and install the Operations Manager Cross Platform Agent on the UNIX/Linux server(s). Running this script will first deploy the agent to the specified UNIX/Linux server and then install it.
The script accepts a list of UNIX/Linux hosts on the input pipe. The hosts are represented either as strings with fully qualified domain names (FQDN) or as objects with a "ComputerName" string property with the FQDN.
The output of the script is a list of objects with a "ComputerName" string property added/changed to contain the FQDN of the Unix/Linux host and a "Status" property added/changed to contain the status of the operation for the current host. All status strings except 'OK' are an error message.
The following parameters can be used with the InstallUnixAgent script:
Parameter | Definition |
Port | Port to connect to at remote host (default is 22) |
RootManagementServer | Name of OpsMgr root management server to use, or empty string to use current computer (default) |
Username | User name to use for connecting to remote host (required) |
Password | Password for specified username (required) |
PackageName | Name of package to install (required, name of package file) |
PackagePath | Full path (on the Operations Manager server) to package being installed (required, name of folder with package file) |
Distro | Distribution or OS name (required, one of AIX, HPUX, Solaris, RHEL or SLES) |
Version | OS version of the remote host (required, one of 11iv2, 11iv3, 4, 5, 5.3, 6.1, 8, 9, 10, 11) |
Architecture | OS architecture of the remote host (required, one of Powerpc, IA64, PARISC, SPARC, x86 or x64) |
Target | Additional remote computer targeted for install (done before any hosts piped into script) |
Usage:
InstallUnixAgent.ps1-Port: <SSH Port Number> - RootManagmentServer :<RMS FQDN>
-Username: <username> -Password: <password> -PackageName: <Agent Package Name>
-PackagePath: <Full Path to Package> -Distro: <Distribution> -Version: <OS Version>
-Architecture: <Architecture> -Target :<Target Computer FQDN>
Example:
To deploy and install the x86 version of the SUSE Linux Enterprise Server 10 (SLES) Agent to the computer named SLES10-1.contoso.com, the following would be used:
InstallUnixAgent.ps1 -Username:root -Password:password -PackageName:scx-1.0.4-248.sles.10.x86.rpm -PackagePath:”C:\Program Files\System Center Operations Manager 2007\AgentManagement\UnixAgents” -Distro:SLES–Version:10 -Architecture:x86
-Target:SLES10-1.contoso.com
Note: The script can also be executed without the parameter names, but all the parameters must be provided.
UpgradeUnixAgent.ps1
The UpgradeUnixAgent script is used to upgrade an existing Operations Manager Cross Platform Agent on a UNIX/Linux server. This is done by first deploying the updated agent to the remote UNIX/Linux server and then installing it (upgrading).
Usage:
UpgradeUnixAgent.ps1-Port: <SSH Port Number> - RootManagmentServer :<RMS FQDN>
-Username: <username> -Password: <password> -PackageName: <Agent Package Name>
-PackagePath: <Full Path to Package> -Distro: <Distribution> -Version: <OS Version>
-Architecture: <Architecture> -Target :<Target Computer FQDN>
Example:
To upgrade an existing SLES agent to a new version (e.g., version 1.0.4-252), you would use the following command:
UpgradeUnixAgent.ps1 -Username:root -Password:password -PackageName: scx-1.0.4-252.sles.10.x86.rpm -PackagePath: ”C:\Program Files\System Center Operations Manager 2007\AgentManagement\UnixAgents” –Distro:SLES –Version:10 –Architecture:x86
–Target: SLES10-1.contoso.com
DiscoverUnixAgent.ps1
The DiscoverUnixAgent script is used to sign the certificate used for communication and discovering an instance of the UNIX/Linux Server into Operations Manager.
The script accepts a list of UNIX/Linux hosts on the input pipe. The hosts are represented either as strings with fully qualified domain names (FQDN) or as objects with a "ComputerName" string property with the FQDN. See Warning section below to avoid potential problems with duplicate discoveries.
The output of the script is a list of objects with a "ComputerName" string property added/changed to contain the FQDN of the Unix/Linux host and a "Status" property added/changed to contain the status of the operation for the current host. All status strings except 'OK' are an error message.
The following parameters can be used with the DiscoverUnixAgent script:
Parameter | Definition | |||||||||||||||||||||||
Port | Port to connect to at remote host (default is 22) | |||||||||||||||||||||||
Server | Name of OpsMgr server to use or empty string to use current computer (default) | |||||||||||||||||||||||
RootManagementServer | Name of OpsMgr root management server to use or empty string to use current computer (default) | |||||||||||||||||||||||
Username | User name to use to connect to remote host (required) | |||||||||||||||||||||||
Password | Password to use to connect to remote host (required) | |||||||||||||||||||||||
Distro | Distribution or OS name (required). (see below for valid combinations of operating systems, versions and architectures) | |||||||||||||||||||||||
Version | OS version of the remote host (required). (see below for valid combinations of operating systems, versions and architectures) | |||||||||||||||||||||||
Architecture | OS architecture of the remote host (required) (see below for valid combinations of operating systems, versions and architectures) | |||||||||||||||||||||||
Target | Additional remote computer to discover (done before any hosts piped into script) | |||||||||||||||||||||||
Valid combinations of operating systems, versions and architectures:
|
Usage:
DiscoverUnixAgent.ps1-Port :<SSH Port Number> -Server :<OpsMgr Server>
-RootManagmentServer :<RMS FQDN> -Username :<username> -Password :<password>
-Distro :<Distribution> -Version :<OS Version> -Target: <Target Computer FQDN>
Example:
To sign the certificate and discover the x86 version of the SUSE Linux Enterprise Server 10 (SLES) Agent to the SLES 10 server named SLES10-1.contoso.com, the following would be used:
InstallUnixAgent.ps1 -Username:root -Password:password -Distro:SLES -Version:10
-Target: SLES10-1.contoso.com
As before, the script can also be executed without the parameter names, however, in these instances all the parameters must be provided.
Warning: When a UNIX/Linux host has been discovered from a particular OpsMgr server, do not run this script to re-discover the same UNIX/Linux host and specify a different OpsMgr server. When re-discovering an existing UNIX/Linux host, always specify the same OpsMgr server from which it was originally discovered. The script does not detect when a different OpsMgr server is specified, and the result is two entries for the same computer in the OpsMgr database. Deleting the extra entry deletes both entries and all history, so you must start fresh in monitoring the UNIX/Linux host.
Chaining the PowerShell Scripts
The Cross Platform PowerShell scripts are designed so that they can be chained together. For example, you may want to deploy, install, sign, and discover a single UNIX/Linux server (or a group of UNIX/Linux servers) by using a single command. This is done the same way other PowerShell scripts are chained together - by piping the output of one command into the input of the next.
However, in these instances, we want to make sure that the output from one command is only piped into the next if the action being performed was successful. For example, if the initial agent installation fails, we don’t want to attempt to discover the server into Operations Manager. This can be done in a couple of ways.
Examples:
This command passes the output from the first script into the second script, but only if the first one was successful:
Type File_of_hosts | InstallUnixAgent.ps1 | Where { $_.Status -eq "OK"} | DiscoverUnixAgent.ps1
This command passes the output from the first script into the second script, but only if the first one was successful. Otherwise, it will write out an error status:
Type File_of_hosts | InstallUnixAgent.ps1 | foreach { if ($_.Status -eq "OK")
{ Write-Output $_ } else { Write-Error $_.Status } } | DiscoverUnixAgent.ps1
This example adds another piped command to return a list of the UNIX/Linux Servers against which the scripts were run and the outcome of each:
Type File_of_hosts | InstallUnixAgent.ps1 | foreach { if ($_.Status -eq "OK")
{ Write-Output $_ } else { Write-Error $_.Status } } | DiscoverUnixAgent.ps1 | Foreach { Write-Host $_.ComputerName $_.Status }
Comments
Anonymous
April 22, 2011
The comment has been removedAnonymous
May 03, 2011
The comment has been removedAnonymous
May 04, 2011
Hi Michael, Your best bet is to post your question in the forums where it will be seen my more people. social.technet.microsoft.com/.../threadsAnonymous
March 19, 2012
Hello, The example for DiscoverUnixAgent.ps1-Port:<SSH Port Number> -Server:<OpsMgr Server> -RootManagmentServer:<RMS FQDN> -Username:<username> -Password:<password> -Distro:<Distribution> -Version:<OS Version> -Target:<Target Computer FQDN> is set to "InstallUnixAgent.ps1" !!! Please could I have an example with DiscoverUnixAgent.ps1 Thanks, DOmAnonymous
July 26, 2012
If not, are there any updates coming?Anonymous
September 07, 2012
A bit of warning. The DiscoverUnixAgent.ps1 will cause insertion of duplicate Xplat agents if you attempt to add a Unix/Linux agent that is already managed but is managed by a different management server than what you are passing in the script. These scripts need to be improved upon to add a check to ensure an agent isn't already managed.Anonymous
October 10, 2012
Please use discretion when using the DiscoverUnixAgent.ps1 script. If you run the script “DiscoverUnixAgent.ps1”, and run it for a server that is already managed but managed by a different MS than the MS you are passing to the script, it will insert a duplicate agent, which can result in unexpected behavior. If by chance this does occur, you can remove the duplicate from the console, but it will remove both instances, so the agent must be redisocered again.Anonymous
October 10, 2012
Note that these scripts will not be carried over to System Center 2012 OpsMgr. The 2012 version has a new set of Powershell cmdlets that implement pretty much the same functionality as these scripts. So in 2012 you should use the cmdlets, which are documented and supported as part of the product.