Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用powershell 3.0在远程服务器2012上安装Windows功能_Powershell_Powershell 3.0_Powershell Remoting_Powershell Ise - Fatal编程技术网

使用powershell 3.0在远程服务器2012上安装Windows功能

使用powershell 3.0在远程服务器2012上安装Windows功能,powershell,powershell-3.0,powershell-remoting,powershell-ise,Powershell,Powershell 3.0,Powershell Remoting,Powershell Ise,考虑到这两个例子,我想知道哪一个是最佳实践。使用内置的帮助示例,我编写了一个脚本,用于在远程服务器上安装windows功能。这是我的密码: $servers = ('server1', 'server2', 'server3', 'server4') ForEach ($server in $servers) { Install-WindowsFeature -Name Desktop-Experience -ComputerName $server -IncludeAllSubFea

考虑到这两个例子,我想知道哪一个是最佳实践。使用内置的帮助示例,我编写了一个脚本,用于在远程服务器上安装windows功能。这是我的密码:

$servers = ('server1', 'server2', 'server3', 'server4')

ForEach ($server in $servers) {
    Install-WindowsFeature -Name Desktop-Experience -ComputerName $server -IncludeAllSubFeature -IncludeManagementTools -Restart
}
还是应该像下面这样将“Install WindowsFeature…”包装在“Invoke Command”块中

Invoke-Command -ComputerName server1, server2, server3, server4 -command {
    Install-WindowsFeature -Name Desktop-Experience -ComputerName $server -IncludeAllSubFeature -IncludeManagementTools -Restart
}

谢谢你的洞察力

在这种情况下,我个人会使用后者(直接调用
安装WindowsFeature-ComputerName$server
,而不是执行单独的
调用命令
),原因如下:

  • 您现在可能正在对功能名称进行硬编码,但将来可能会希望将其放入变量中。如果将它们放入变量中,则必须将其作为参数传递到
    Invoke命令的脚本块中。这是完全可能的,但需要做更多的工作
  • 通过使用自己的循环,您可以编写进度消息、日志记录等
  • 在这种情况下,使用
    Invoke Command
    没有任何好处,因为您在远程计算机上运行一个命令(而不是使用
    -ComputerName
    参数运行多个命令,而不是在脚本块内运行多个命令)