PowerShell远程重启IIS和Service
测试要连接的电脑开没开远程
Test-WsMan 192.168.1.1
或者直接在远程电脑查看
Get-Service WinRM
如果没开的话打开
Enable-PSRemoting –Force
连接之前需要信任远程的电脑
查看TrustedHosts列表get-item wsman:\localhost\Client\TrustedHosts将所有计算机都添加到TrustedHosts列表set-item wsman:\localhost\Client\TrustedHosts -value *将一个域里的所有计算机都添加到TrustedHosts列表set-item wsman:\localhost\Client\TrustedHosts -value *.omg.com将指定计算机名的计算机添加到TrustedHosts列表set-item wsman:\localhost\Client\TrustedHosts -value <ComputerName>将一个IP地址添加到TrustedHosts列表set-item wsman:\localhost\Client\TrustedHosts -value 192.168.1.2
进入会话
Enter-PSSession 192.168.1.1 -Credential "OMG\admin"
分享链接
Windows PowerShell 帮助
about Remote Troubleshooting - PowerShell | Microsoft Docs
PowerShell 在线教程 – PowerShell 中文博客
自动使用管理员身份运行
$currentWi = [Security.Principal.WindowsIdentity]::GetCurrent()
$currentWp = [Security.Principal.WindowsPrincipal]$currentWiif( -not $currentWp.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
$boundPara = ($MyInvocation.BoundParameters.Keys | foreach{
'-{0} {1}' -f? $_ ,$MyInvocation.BoundParameters[$_]} ) -join ' '
$currentFile = (Resolve-Path? $MyInvocation.InvocationName).Path$fullPara = $boundPara + ' ' + $args -join ' '
Start-Process "$psHome\powershell.exe"?? -ArgumentList "$currentFile $fullPara"?? -verb runas
return
}
自动实现重启IIS的Application Pool
$IP = '192.168.1.1'
$Username = 'omg\administrator'
$Password = 'laotie666'$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass$s = New-PSSession $IP -Credential $CredInvoke-Command $s -ScriptBlock { Restart-WebAppPool -Name "Test" }
自动重启远程的Service
Invoke-Command $IP -Credential $Cred -ScriptBlock { Get-Service -Name 'Test' | Restart-Service -Force }
PowerShell远程重启IIS和Service相关推荐
- iisreset远程重启IIS服务提示没有注册类
今天在Windows Server 2008 R2下尝试用命令行重启IIS,系统提示"没有注册类".查了下可能是是IIS安装时dll没注册成功,运行以下命令即可: C:\Windo ...
- windows服务器远程重启又好,net use与shutdown配合使用,本机重启远程服务器
net use与shutdown配合使用,本机重启远程服务器 今天服务器出现问题了,能ping通,但就是远程登录服务器后,服务器无法响应. 在本机测试发现ftp服务可以使用,于是就想通过ftp就行重启 ...
- PowerShell 远程执行命令
PowerShell 远程执行命令 https://www.cnblogs.com/wanghao4023030/p/11151099.html 最近在做一些自动化的测试工作,在代码实现的过程中需要远 ...
- 【实战】Windows使用任务计划执行批处理定时重启IIS部署的网站
文章目录 一.windows定时任务 1.Windows 任务计划程序 2.Windows Service 二.命令行方式启停IIS网站 三.例:定时启停IIS网站 目标任务 步骤 查看成果 一.wi ...
- Windows 10下,如何使用PowerShell批量重启局域网电脑
PowerShell 在Windows 10中越来越受到微软重视,甚至被微软安排在开始按钮超级菜单中替换了一直以来默认的命令提示符(当然还可以换回去),这和该工具越来越强大密不可分.这次就介绍一个&q ...
- 使用 Powershell 远程连接 windows server
使用 Powershell 远程连接 windows server Intro 最近我们的开发环境增加了一个 windows 服务器,没有界面的,不能直接远程桌面连上去管理,需要使用 Powershe ...
- win7系统如何重启服务器,云骑士解决win7系统重启IIS服务的技巧介绍
大部分电脑爱好者在使用win7企业版系统的时候,会频繁遇见win7系统重启IIS服务的麻烦,比如近日有用户到本站反映说win7系统重启IIS服务的情况,只是却不明白要怎么样操作win7系统重启IIS服 ...
- 怎么打云开服务器iis_云服务器怎么重启iis
Net 命令操作 1.在计算机中点击"开始"-"运行",输入cmd 打开命令窗口: 2.输入 net stop iisadmin /y 回车停止IIS:再输入 ...
- 服务器退出安全狗服云,安全狗服云远程重启服务器的方法分享
安全狗服云如何远程重启服务器?安全狗服云是一款功能强大的服务器安全管理软件,实时告警信息也将全部通过告警消息的方式推送到客户端,让您无需登录服务器,就可以轻松掌握服务器与网站的安全状态.除此之外它还能 ...
最新文章
- Mysql 面试复习
- CXF wsdl2java 生成java代码供客户端使用
- [编写高质量代码:改善java程序的151个建议]建议31-在接口中不要存在实现代码...
- boost::callable_traits的is_invocable的测试程序
- 切记:只有肯吃苦才能赚大钱!
- 图片存储解决方案的分析
- 怎么看服务器上jdk安装位置,查看云服务器jdk安装路径
- python语言开发环境搭建_Python开发环境搭建-Go语言中文社区
- hadoop2.6.集群搭建
- c#明华rf读卡器_明华URF-R330读卡器C#代码示例
- leetcode 咒语和药水的成功对数
- 【应急响应】Linux下变种DDG挖矿应急处理总结
- php 验证 手机号码
- html5+css3布局尝试
- 毛利率、净利率和成本利润率的区别是什么 ?
- Verilog HDL——运算符
- ADO数据库连接中的Persist Security Info参数的作用
- 安卓手机反应慢又卡怎么办_安卓手机反应慢怎么办?一分钟教你加速!
- ChatGPT原理解析以及使用方法介绍
- uni-app底部安全区高度(padding-bottom、bottom)