跟进这个问题(无法远程设置 SCOM 维护模式)
我们正在尝试将服务器远程置于维护模式。我正在使用 Tom Schumacher 创建的 SCOM 函数(https://gallery.technet.microsoft.com/scriptcenter/Put-server-in-Maintenance-0a23e1fe)
我正在使用 PSSession 尝试从 SCOM 服务器以外的服务器将服务器置于维护模式:
. C:\Scripts\Start-serverScommaintenance.ps1
$s = New-PSSession -ComputerName scomserver
Invoke-Command -Session $s -Scriptblock {Import-Module OperationsManager}
Invoke-Command -Session $s -Scriptblock ${function:Start-
serverScommaintenance}
Invoke-Command -Session $s -Scriptblock {Start-serverScommaintenance -
servername testserver -message "test" -maintmodeinMinutes '6'}
当我到达该功能时,我收到以下错误:
无法验证参数“DisplayName”上的参数。参数为 null 或空。提供一个不为 null 或空的参数,然后重试该命令。+ CategoryInfo : InvalidData: (:) [Get-SCOMClassInstance], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.SystemCenter.OperationsManagerV10.Commands.GetSCClassInstanceCommand + PSComputerName : scomserver
术语“Start-serverScommaintenance”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。+ CategoryInfo : ObjectNotFound: (Start-serverScommaintenance:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException + PSComputerName : scomserver
这是用于参考的函数的副本:
function Start-ServerScommaintenance
{
param([string] $servername = 'yourServerGoeshere',
[string]$message = "Putting: $servername into Maintenance Mode via automation",
[int]$maintModeinMinutes = '60')
$funcName = 'func - Start-ServerScommaintenance:'
if(get-command -Name 'Get-SCOMClassInstance')
{
$server = (Get-SCOMClassInstance -DisplayName "$servername*") | select -first 1 | select -ExpandProperty Displayname
$scommanagementServers = (Get-SCOMManagementServer).displayName
if($scommanagementServers -ccontains $server)
{
Write-Warning "$funcname contains a Management Server $server.. You cannot put a management server in Maintenance Mode!!!"
}
else
{
$time = ((get-date).AddMinutes($maintModeinMinutes))
$serverClassIds = Get-SCOMClassInstance -DisplayName $server
foreach($classid in $serverClassIds)
{
$server1 = Get-SCOMClassInstance -id ($classid.id) | Where-Object{$_.DisplayName -match $server}
write-host "$funcName putting " ($server1.id) ' in maintenance Mode Servername -->' ($Server1.DisplayName)
if(!(Get-SCOMMaintenanceMode -Instance $classid))
{
Start-SCOMMaintenanceMode -Instance $server1 -EndTime $time -reason PlannedOther -Comment $message
}
else
{ Write-host "$funcname " $classid.id " has already been placed in Maintenance Mode"}
}
}
}
else
{ Write-host "$funcname doesn't have the Operationsmanager module imported for this session"}
}
function Stop-ServerScommaintenance
{
param([string] $servername = 'yourServerGoeshere',
[string]$message = "Removing Maintenance Mode from: $servername via automation"
)
$funcName = 'func - Stop-ServerScommaintenance:'
if(get-command -Name 'Get-SCOMClassInstance')
{
$server = (Get-SCOMClassInstance -DisplayName "$servername*") | select - first 1 | select -ExpandProperty Displayname
$scommanagementServers = (Get-SCOMManagementServer).displayName
if($scommanagementServers -ccontains $server)
{
Write-Warning "$funcname contains a Management Server $server.. You cannot put a management server in Maintenance Mode!!!"
}
else
{
$serverClassIds = Get-SCOMClassInstance -DisplayName $server
foreach($classid in $serverClassIds)
{
$server1 = Get-SCOMClassInstance -id ($classid.id) | Where- Object{$_.DisplayName -match $server}
write-host "$funcName removing " ($server1.id) ' in maintenance Mode Servername -->' ($Server1.DisplayName)
$result = (Get-SCOMClassInstance -id ($classid.id)|Where-Object{$_.Displayname -like $servername}).StopMaintenanceMode((get-date).ToUniversalTime())
}
}
}
else
{ Write-host "$funcname doesn't have the Operationsmanager module imported for this session"}
}
#Start-serverScommaintenance -servername Server1 -message "my message" -maintmodeinMinutes '30'
#Stop-ServerScommaintenance -servername Server1 -message "my message"