首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法远程设置SCOM维护模式

无法远程设置SCOM维护模式
EN

Stack Overflow用户
提问于 2016-09-23 19:42:05
回答 1查看 597关注 0票数 0

我们正在尝试远程将服务器设置为维护模式。我使用的是SCOM functions created by Tom Schumacher

如果我在SCOM服务器上执行以下操作,该过程将完成,并且我能够将服务器置于维护模式并再次停止它:

代码语言:javascript
复制
#load the function
. C:\temp\opsmanagerFunctions.ps1

#Import the OpsMgr module
Import-Module OperationsManager

#Set server into maintenance mode
Start-serverScommaintenance -servername testserver -message "test" -maintmodeinMinutes '6'

#Stop server maintenance mode
Stop-ServerScommaintenance -servername testserver -message "test complete"

这一切都很好,但是我正在尝试从另一台服务器运行上述进程,该服务器将运行其他几个进程,这些进程要求服务器首先处于维护模式。

我的直通车是从辅助服务器运行以下命令:

代码语言:javascript
复制
#1
C:\temp\opsmanagerFunctions.ps1

#2
Invoke-Command -ComputerName scomservername -ScriptBlock {Import-Module OperationsManager}

#3
Invoke-Command -ComputerName scomservername ${function:Start-serverScommaintenance} 

#4
Invoke-Command -ComputerName scomservername -ScriptBlock {Start-serverScommaintenance -servername testserver -message "test" -maintmodeinMinutes '3'}

#5
Invoke-Command -ComputerName scomservername -ScriptBlock {Stop-ServerScommaintenance -servername testserver -message "test complete"}

但是,在尝试在远程机器上运行该函数(步骤3)之后,我得到以下错误:

代码语言:javascript
复制
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
path is correct and try again.
    + CategoryInfo          : ObjectNotFound: (Get-SCOMClassInstance:String) [Get-Command], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
    + PSComputerName        : scomserver
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-23 20:00:20

通过这样使用Invoke-Command

代码语言:javascript
复制
Invoke-Command -ComputerName scomservername -ScriptBlock {Import-Module OperationsManager}

您创建一个会话,执行import命令并结束会话。因此,下一次调用不会加载模块,脚本也会失败。

使用会话继续使用上下文,如下所示:

代码语言:javascript
复制
$s = New-PSSession -ComputerName foo
Invoke-Command -Session $s -Scriptblock { <whatever> }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39659931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档