I'm not going to attempt to rewrite your script for you, but you need to do something like this:
$fileinput = Get-Content c:\tags.txt
foreach ($tag in $fileinput)
{
Write-Host $tag
# Or whatever it is you're trying to do here
}
Question
The script below asks for the $tag1
variable and uses that, but instead of entering in 1 variable at a time, I want to load a text file with many variables. I know you can use Get-Content c:\scripts\test.txt | Foreach-Object
but I am not sure how to use it in this situation.
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
}
La solution
I'm not going to attempt to rewrite your script for you, but you need to do something like this:
$fileinput = Get-Content c:\tags.txt
foreach ($tag in $fileinput)
{
Write-Host $tag
# Or whatever it is you're trying to do here
}