我不太擅长 PowerShell,所以希望您能查找正确的语法。但 ...
一种选择是运行 Powershell 脚本并检查会话计数,如下所示:
更新:将“会话总数”更改为“活动会话”
write-host Getting performance counters ...
$perfCounterString = "\asp.net applications(__total__)\sessions active"
$counter = get-counter -counter $perfCounterString
$rawValue = $counter.CounterSamples[0].CookedValue
write-host Session Count is $rawValue
if( $rawValue -gt 0)
{
write-host Session are active - will not stop IIS
exit
}
write-host Stopping IIS
stop-service "IISAdmin"
# Set values
$webConfig = "d:\web.config"
$newTimeout = "20"
# Open file and change value
$doc = new-object System.Xml.XmlDocument
$doc.Load($webConfig)
$doc.SelectSingleNode("//sessionState").timeout = $newTimeout
$doc.Save($webConfig)
write-host Starting IIS
start-service "IISAdmin"
write-host Done!
Run Code Online (Sandbox Code Playgroud)
将其保存在桌面上,名称为“ChangeIIS.ps1”。
现在,Powershell 不喜欢您只运行 .bat 文件等脚本。出于安全原因,您必须授予对进程或您的用户的访问权限。所以请执行以下操作:
powershellSet-ExecutionPolicy -scope process Bypasssl <path to directory of .sp1 file>。sl[set-location] 就像cd命令提示符中一样$ '.\ChangeIIS.ps1'它将立即运行并重置该值。
这是我的博客的链接,介绍了我如何 以更分步的方式创建 PowerShell 脚本
| 归档时间: |
|
| 查看次数: |
6391 次 |
| 最近记录: |