Verifies the sum of files in a folder for a list of computers instead of the sum of files in a folder on my computer only

StackOverflow https://stackoverflow.com/questions/20294866

Frage

Please help me. I Need to change this statement so that it verifies the sum of files on a folder from a list of computers on a text file, rather than verifying the sum of that same folder that resides on my computer only? We have the root of our computers shared as c$ if that helps. The end result will have incorrectsumoffiles.txt contain a list all computers that returned true from the query.

(gci c$\800patchfolder -recurse).Count -ne 345 | out-file incorrectsumoffiles.txt

I think the correct syntax would look something like this... get-content computerlist.txt | query | output But powershell requires a evaluation prior to any piping? The out-file being incorrectsumoffiles.txt will only contain names of computers that returned "true" from the -ne comparison operator. Thank You.

War es hilfreich?

Lösung

Use Get-Content to read your list of computers, then iterate through each one to check the count, and if it is not correct append it to your txt file.

Something like this should do what you are asking:

$computers = Get-content C:\listofcomputers.txt

Foreach ($computer in $computers){

If ((gci \\$computer\c$\800patchfolder -recurse).Count -ne 345) {
$computer | out-file c:\incorrectsumoffiles.txt -append
}

} 
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top