我想知道考虑到这两个示例可能会起作用,哪个是最佳实践。使用内置帮助示例,我编写了一个脚本来在远程服务器上安装 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
}
感谢您的洞察力!