【发布时间】:2019-09-09 01:22:27
【问题描述】:
在两个 VNC 服务器强制关闭 MS 登录组时遇到问题。我正在对问题进行故障排除,我想做的一件事是监视配置 .ini 文件。我对 PowerShell 比较陌生,不能完全让它工作。
基本上,我希望脚本检查配置文件 (ultravnc.ini) 的内容并查看“MSLogonRequired=1”是否是该文件中的字符串。如果没有,我想将日期附加到日志文件中。最终我会做更多的事情,但这是我的基本需求。它目前不工作。
# Variables
$outputFile = "vncMSLogonErrors.txt"
$vncConfig = "C:\Program Files (x86)\uvnc bvba\UltraVNC\ultravnc.ini"
$checkString = "MSLogonRequired=1"
# Get VNC Config File, check for MS Logon setting, write date to file if missing
Get-Content $vncConfig
If (-not $checkString)
{Add-Content $outputFile -Value $(Get-Date)}
【问题讨论】:
-
使用
Get-Content加载文件,遍历它,如果没有找到检查字符串,则添加它。 -
if((Get-Content $vncConfig -raw) -notmatch $checkString){Set-content $outputFile -Value $(Get-Date) -Append}
标签: powershell ini