# Name:
# Date: 02/13/2023
# Desc: Runs remote commands for every computer within domain to collect general information
#Defining variable that reads the computer names from the .txt file
$ADCS = Get-Content -Path "C:\computers.txt"
# Loop through each computer name in the list
foreach ($ADC in $ADCS) {
# Run the Invoke-Command cmdlet for each computer
Invoke-Command -ComputerName $ADC -ScriptBlock {
Get-ComputerInfo | Out-file -FilePath C:\Users\xml\Documents\computerinfo.txt -Append
}
}
When this command is run, the results are not shown in the terminal, and instead look like they’re being redirected to the txt file. However, the text file is never created. What am I missing?
That makes a lot of sense… I have been checking my local path. With that being said the solution is simply changing the path location to a shared location right?
Yes, you could use a shared location. Alternatively, Invoke-Command will receive the output from the remote computer, so you could just move the Out-File:
foreach ($ADC in $ADCS) {
# Run the Invoke-Command cmdlet for each computer
Invoke-Command -ComputerName $ADC -ScriptBlock {
Get-ComputerInfo
} | Out-file -FilePath C:\Users\xml\Documents\computerinfo.txt -Append
}
Yep, thank you again. I originally put the pipe outside of the for loop, and was receiving an empty pipeline error. So you actually answered both questions.