PowerShell to install SCOM agent...

Well I have been busy!

Looking at all the PowerShell I've been pasting together from bits and pieces found around the web (Thanks Google!) it's no wonder that I've been AFK or more correctly AFB for a couple of months.

But now back with some PowerShell script-lets under my belt and here's one of them.

We have issues *cough* "firewall ports" accessing some of our servers in our remote data centres to push the SCOM agent.

We were unable to solve the *cough* "firewall ports" issue so we decided to go round the issue and manually install the agent on each server.

I wrote a PowerShell and VBS script to accomplish this.  Here there are.  Nothing fancy and I am sure that things could be done better however this is how we are acheiving bypassing our firewall....errr I mean resolved our issue.

The install is silent so you may want to adjust the MSI line and remove /quiet and /qn to help with troubleshooting this script in your environment.


PowerShell version:

# Powershell script to install and configure the Ops Manager Agent
# Ver. 1.0

# Use at your own risk!
$path_to_install = <your-path>

# Grab the machine name
$machine = get-content env:Computername
$FQDN = [system.net.dns]::GetHostEntry($Machine).HostName

# Get architecture
$os = get-wmiobject -class "Win32_OperatingSystem" -namespace "root\CIMV2"

if($os.OSArchitecture -eq "64-bit" -or $os.Caption -match "x64"){
 $path_to_install += "\amd64\MOMAgent.msi"
}
else{
 $path_to_install += "\x86\MOMAgent.msi"
}

# Setup Arguments
$args = "USE_SETTINGS_FROM_AD=0 MANAGEMENT_GROUP=MG-Europe MANAGEMENT_SERVER_DNS=<server name> SECURE_PORT=5723 ACTIONS_USE_COMPUTER_ACCOUNT=1"

$args = "/i " + $path_to_install + " /quiet /qn /promptrestart " + $args
# Install Ops Manager Agent
start-process -FilePath "msiexec.exe" -ArgumentList $args



VBScript: 
' VisualBasic script to install and configure the Ops Manager Agent
' Ver. 1.0

' Use at your own risk!
path_to_install = <your path>

' Grab the machine name
Set objWMI = GetObject( "winmgmts:\\.\root\cimv2")
Set colItems = objWMI.ExecQuery("Select * from Win32_ComputerSystem", ,48)

' Yes this is a collection so we have to ForEach it!
For Each objItem in colItems
 FQDN = objItem.Name & "." & objItem.Domain
 ' msgbox FQDN
Next

' Get architecture it is a collection AGAIN!
Set objProcs = objWMI.ExecQuery("Select * from Win32_Processor", ,48)

For Each objProc in objProcs
 If objProc.AddressWidth = "64" then
  path_to_install = path_to_install & "\amd64\MOMAgent.msi "
 Else
  path_to_install = path_to_install & "\x86\MOMAgent.msi "
 End If
Next

' Setup Arguments
args = " USE_SETTINGS_FROM_AD=0 MANAGEMENT_GROUP=MG-Europe MANAGEMENT_SERVER_DNS=<MS server name> SECURE_PORT=5723 ACTIONS_USE_COMPUTER_ACCOUNT=1"

Set objShell = CreateObject("WScript.Shell")

' Install Ops Manager Agent
objShell.Run "msiexec.exe /i " & path_to_install & " /quiet /qn /promptrestart " & args


Enjoy

Comments

Popular posts from this blog

PXE booting, MDT and 802.1x

Intune installation requires a wire...or does it?

Security Policy 1001