我是一个全新的编码新手,正在将这个脚本转换为Powershell。我对first for循环感到困惑。"skip=2“在做什么,%%A是什么,运行系统信息的意义是什么?
@echo off
SET file=f:\srvapps\webdata\wwwroot\VMuptime\HMIlist.txt
SET OUpath="OU=Packaging,OU=Process Control,OU=XP Workstations Remediated,DC=fcb,DC=corp,DC=anheuser-busch,DC=com"
SET output=f:\srvapps\webdata\wwwroot\VMuptime\uptimes.txt
SET modified=f:\srvapps\webdata\wwwroot\VMuptime\modifiedUptimes.txt
setlocal enabledelayedexpansion1
If exist %output% del /F %output%
If exist %modified% del /F %modified%
rem pause
date /T >>%output%
for /F "skip=2" %%A in (%hmi%) do (
systeminfo /s %%A | findstr /c:"System Up Time" /c:"Host Name">>%output%
)
rem pause
date /T >>%modified%
for /F "tokens=1-10" %%G in (%output%) do (
if "%%G"=="Host" (
set line1=%%I
) else echo !line1!, %%J %%K %%L %%M %%N %%O>>%modified%
) 发布于 2021-01-02 07:55:06
这更像是一个.bat文件问题。%hmi%是此处未显示的设置为文件名的变量。然后,skip=2跳过文件中的2行,并将%%A设置为之后文件中的每个主机名。在每个主机名上运行systeminfo,并在输出中搜索正常运行时间。
powershell中的这一部分将是:
$hmi = 'file'
foreach ($a in get-content $hmi | select-object -skip 2) {
systeminfo /s $a | select-string 'system up time','host name'
}当我尝试它的时候,我得不到正常工作时间。
https://stackoverflow.com/questions/65395214
复制相似问题