0

我们已将系统警报移至 SCOM 2012,并在服务器脱机时接收心跳警报。目前,我管理的 vDC 中大约有 750 台服务器。SCOM 2012 服务器位于不同的不受信任域中。

我有一个工作脚本,它将服务器置于维护模式,但它连续运行,大约需要 40 分钟才能将近 400 台服务器置于维护模式。这是一个可行的解决方案,但我想使用 foreach -parallel 命令来加速它。

我创建了我的工作流(使用 foreach -parallel 命令)并将其放置在源计算机和目标计算机上的默认 PowerShell 模块位置之一。我已经在 SCOM 服务器上的工作流之外测试了这组命令,它运行成功。当我尝试通过调用命令远程运行该命令时,SCOM 命令返回为无法识别。

#Get Date for usage in Connection Name
$Date = Get-Date -Format HHmmsss
#combine Name with Date to uniquify
$name = "ScomMM" + $Date

#Collect Servers from WSUS Server 
[reflection.assembly]::LoadWithPartialName("Microsoft.Updateservices.Administration") | out-null
$WSUS = [Microsoft.updateservices.administration.adminproxy]::Getupdateserver("ServerName",$false,8530);
$TS = $wsus.getcomputertargetgroups() | ? {($_.name -eq "Group1") -or ($_.Name -eq "Group2")}
$computers = $TS.getcomputertargets() | Select-Object FullDomainName

#Setup Trusted host 
invoke-Command -ScriptBlock {(winrm.cmd s winrm/config/client '@{TrustedHosts="*PublicIPAddress*"}')}
Enable-PSRemoting -Force
#Credentials stored in a file
$username = "username"
$password = get-content 'Path' | convertto-securestring
$creds = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password
$session = new-PSSession -ComputerName "IPAddress" -Credential $creds -Name $name

#SCOM Commands Module
Import-Module OperationsManager

#Workflow
Import-Module Set-MM

#Run the command remotely
Invoke-Command -Session $session -ScriptBlock {
    Import-Module -Name Set-MM
    Set-MM -computers $using:computers
}

#Workflow - Stored at C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Set-MM\Set-MM.psm1
Workflow Set-MM
{
    Param($computers)
    Foreach -Parallel($computer in $computers)
    {
        Get-SCOMClassInstance -Name $computers.FullDomainName | Start-SCOMMaintenanceMode -EndTime (Get-Date).AddMinutes(6) -Reason PlannedOperatingSystemReconfiguration
    }
}

At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Set-MM\Set-MM.psm1:6 char:3
+         Get-SCOMClassInstance -Name $computers.FullDomainName | Start ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cannot find the 'Get-SCOMClassInstance' command. If this command is defined as a workflow, ensure it is 
defined before the workflow that calls it. If it is a command intended to run directly within Windows 
PowerShell (or is not available on this system), place it in an InlineScript: 'InlineScript { 
Get-SCOMClassInstance }'
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : CommandNotFound
    + PSComputerName        : IPAddress

The term 'Set-MM' is not recognized as the name of a cmdlet, function, script file, or operable program. 
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    + CategoryInfo          : ObjectNotFound: (Set-MM:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName        : IPAddress    

        Get-PSSession | Remove-PSSession

如果我在 foreach -Parallel 内的脚本上使用 Inlinescript

InlineScript{Get-SCOMClassInstance -Name $Using:computers.FullDomainName | Start-SCOMMaintenanceMode -EndTime (Get-Date).AddMinutes(6) -Reason PlannedOperatingSystemReconfiguration}

我为每台试图在工作流中处理的计算机得到这个:

The term 'Get-SCOMClassInstance' is not recognized as the name of a cmdlet, function, script file, or 
operable program. Check the spelling of the name, or if a path was included, verify that the path is 
correct and try again.
    + CategoryInfo          : ObjectNotFound: (Get-SCOMClassInstance:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName        : ServerName
4

0 回答 0