Asked by:
SCOM Maintenance mode remote server

-
I am trying to use below script for putting a server from command line in Maint mode. This maint mode needs to be configured from remote server and not from Management server or server which has SCOM console installed. This script is working perfectly fine except accepting the server name from command line parameter. Can you help with what modification required so that I can pass a command line parameter like .\scriptname.ps1 -server servername.com
param
(
[string]$server
)
$Session = New-PSSession -ComputerName XXX.yyy
$Session = Get-Pssession
Invoke-Command -Session $Session -ScriptBlock {
Param($server)
Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"
Set-Location "OperationsManagerMonitoring::"
$mgConn = New-ManagementGroupConnection -ConnectionString:scomms.jp-pcimng.local
$Agents = Get-Agent
Import-Module –Name OperationsManager
$MS ="xxx.yyy"
New-SCOMManagementGroupConnection $MS -ErrorAction SilentlyContinue -ErrorVariable Err |out-null
Write-host "Putting $Server into MM"
$Time = (Get-Date).addMinutes(1051200)
$instance = (get-scomclass -DisplayName "Windows Computer" |Get-SCOMClassInstance | ? { $_.DisplayName -eq $Server } )
Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Comment "Applying software update." -Reason "SecurityIssue"
}
Remove-PSSession -Session $Session
Question
All replies
-
1) any error message ?
2) >>This script is working perfectly fine except accepting the server name from command line parameter.
Does it means following script work fine in remote server?
*********************************
<#
param
(
[string]$server
)
#>$Session = New-PSSession -ComputerName XXX.yyy
$Session = Get-PssessionInvoke-Command -Session $Session -ScriptBlock {
Param($server)Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"
Set-Location "OperationsManagerMonitoring::"
$mgConn = New-ManagementGroupConnection -ConnectionString:scomms.jp-pcimng.local
$Agents = Get-Agent
Import-Module –Name OperationsManager
$MS ="xxx.yyy"
New-SCOMManagementGroupConnection $MS -ErrorAction SilentlyContinue -ErrorVariable Err |out-null
Write-host "Putting $Server into MM"
$Time = (Get-Date).addMinutes(1051200)
# $instance = (get-scomclass -DisplayName "Windows Computer" |Get-SCOMClassInstance | ? { $_.DisplayName -eq $Server } )
$instance = (get-scomclass -DisplayName "Windows Computer" |Get-SCOMClassInstance | ? { $_.DisplayName -eq 'servername.com' } )
Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Comment "Applying software update." -Reason "SecurityIssue"
}
Remove-PSSession -Session $Session
****************************************************
Roger -
Yes correct. If you provide the server name in the script then it works perfectly fine. However when you try to provide the server name using command line parameter like .\scriptname.ps1 -server servername.com then somehow it does not accept the server name script fails.