前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >powershell批量远程示例,批量给多台机器安装dotnet和iis

powershell批量远程示例,批量给多台机器安装dotnet和iis

原创
作者头像
Windows技术交流
修改2024-01-30 20:08:18
1.4K0
修改2024-01-30 20:08:18
举报
文章被收录于专栏:Windows技术交流Windows技术交流

对服务端机器(被远程的机器),除过termservice服务正常运行、远程端口正常监听外,还要额外以管理员身份执行一句powershell命令:

代码语言:javascript
复制
winrm quickconfig -q 2>&1> $null;winrm quickconfig -q -force 2>&1> $null;netstat -ano|findstr :5985;

确保5985是监听的才行。

以下代码兼容server2008r2/2012r2/2016/2019/2022

对客户端机器,如果5985端口不在会报错

powershell命令:

代码语言:javascript
复制
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM" /f 2>&1 >$null
#stop-service mpssvc 2>&1 > $null
winrm quickconfig -q 2>&1 > $null
winrm quickconfig -q -force 2>&1 > $null
restart-service winrm 2>&1 > $null
#Set-Item WSMan:localhost\client\trustedhosts -value * -force 2>&1 > $null
winrm set winrm/config/client '@{TrustedHosts="*"}' 2>&1 > $null
netstat -ato|findstr :5985
Set-Item WSMan:localhost\client\trustedhosts -value * -Force

如果上面这段代码配置winrm报错-2147024894 0x80070002就是得装补丁,参考我整理的文档https://cloud.tencent.com/developer/article/2043723

先打全补丁,参考我这篇文档里微软的更新脚本来更新:https://cloud.tencent.com/developer/article/2345790

然后检查注册表,删掉HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WinRM

代码语言:powershell
复制
Registry Path:HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WinRM

powershell:reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM" /f 2>&1 >$null

cmd:reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WinRM" /f 2>&1 >nul

powershell批量远程示例,批量给多台机器安装dotnet和iis:

代码语言:powershell
复制
$Username = 'Administrator'
$Password = '明文密码'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

$iparray = @('172.21.66.32','172.21.65.41','172.21.65.162')

for($i=0;$i -lt $iparray.Length;$i++){
"`$iparray["+$i+"]="+$iparray[$i]+"`n"
Invoke-Command -ComputerName $iparray[$i] -Credential $Cred -ScriptBlock { 
Get-WindowsFeature -Name NET-*, Web-* | where {$_.Name -notmatch "Ftp|Web-Application-Proxy"} | Install-WindowsFeature;
}
}

上面黑体的部分就是要批量下发的指令,多行的话用英文分行隔开,比如要批量下发停止云监控组件和禁止云监控组件开机运行的命令

代码语言:powershell
复制
sc.exe stop BaradAgentSvc 2>$null 1>$null;sc.exe stop StargateSvc 2>$null 1>$null;sc.exe config BaradAgentSvc start= disabled  2>$null 1>$null;sc.exe config StargateSvc start= disabled  2>$null 1>$null;

如果是批量删除C:\Program Files\QCloud\Monitor\Barad\ntpdate.exe

那就批量下发

del C:\progra~1\QCloud\Monitor\Barad\ntpdate.exe 2>$null 1>$null;

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档