下面的脚本要求$tag1
变量并使用它,但我不想一次输入1个变量,而是要加载一个包含许多变量的文本文件。我知道您可以使用Get-Content c:\scripts\test.txt | Foreach-Object
,但我不确定如何在这种情况下使用它。
Get-Content C:\Users\ajstepanik\Desktop\tags.txt | Foreach-Object { write-host $_
#Windows XP
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $tag1)
$key = $reg.OpenSubKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon')
$winxp = $key.GetValue('DefaultUserName') -replace '^.*?\\'
#Windows 7
$reg1 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $tag1)
$key1 = $reg1.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI')
$win7 = $key1.GetValue('LastLoggedOnUser') -replace '^.*?\\'
set-alias psloggedon 'C:\Users\ajstepanik\Desktop\PSTools\PsLoggedon.exe'
echo "Windows XP"
echo "----------"
echo $winxp
"`n"
echo "Windows 7"
echo "----------"
echo $win7
"`n"
$pstools = psloggedon \\$tag1
echo $pstools
}
答案 0 :(得分:1)
我不会尝试为您重写脚本,但您需要执行以下操作:
$fileinput = Get-Content c:\tags.txt
foreach ($tag in $fileinput)
{
Write-Host $tag
# Or whatever it is you're trying to do here
}