powershell - Need windows script to run simple for loop across all the parameters listed in a text file -
i need run windows "net view" command against each of these values in test.txt file.
test.txt contains list of servers below:
\\lb042073 \\lb042425 \\lb042507 \\lb045196
i need run "net view" command against each of these servers.
below command not work:
get-content test.txt | %{& net view}
thanks in advance.
in powershell:
get-content test.txt | %{net view $_}
get-content
- read file outputting each line individually
|
- pipeline character. works same in windows , *nix. passes output of 1 command input of next command
%
- alias foreach-object
. loop construct code each object in list
{
- beginning of code block
net view $_
- runs net.exe
program passing 2 parameters view , contents of special $_
variable. $_
variable in foreach-object
loop holds input item current iteration of loop.
}
- end of code block
Comments
Post a Comment