WeTi
asked on
Powershell one liner, measure the file count in server list.
Dear expert
Please help with the code below.
Please help with the code below.
Get-Content -Path C:\Scripts\serverlist.txt | Where-Object {Get-ChildItem -File -Path $_} | ForEach-Object {"File in $_"}
This one liner shows: in serverlist.txt if there is file in it or not, now I would like add a count in each server list how many files in there. i tried with |measure| but I don't know how to use it, anyone can assist? I would see the output: File in \\servernamn\ and number after. Thanks
ASKER
Hi thanks for reply, output result:
\\server1\folder 0
\\server2\folder 3
Just simple as that I changed abit in my code:
\\server1\folder 0
\\server2\folder 3
Just simple as that I changed abit in my code:
$server= Get-Content -Path C:\Scripts\serverlist.txt
ForEach($server in $servers) {
gci -path $server | where {!$_.PSIsContainer} | Measure-Object
"File in $server" }
Im still trying to figuer it out.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Very fast indeed but maybe too fast, I change the code abit, thanks.
Now works
$servers = Get-Content -Path C:\Scripts\serverlist.txt
ForEach ($server in $Servers) {
$count = (Get-ChildItem -File -Path $server -ErrorAction SilentlyContinue | Measure-Object).Count
If ($count -gt 0) {
"$($count) Files in $($server)"
}
}
Now works
Then: How should that work? Should the script guess the share names?