ForEach – Remote Enumeration
- This topic has 5 replies, 3 voices, and was last updated 2 years, 4 months ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.
Home › Forums › Scripting › PowerShell › ForEach – Remote Enumeration
This may seem remedial – but I struggle with PS. Specifically with remote management.
Need to enumerate (with size) profiles located on remote PCs
The following script works on the local
Local
(this returns the desired data on local)
[SIZE=11px]dir c:users|foreach-begin {} -process{
$size=(dir$_.FullName -recurse-force-easilentlycontinue|Measure-Object‘length’-sum-Maximum).sum
write-host(“{0:n2}”-f ($size/1MB) +” MB”,$_.fullname)[/SIZE]
[SIZE=8px][SIZE=8px]} [/SIZE][/SIZE]
Attempting to adjust for remote use:
(This returns the directory name on local- no size)
$computers =Read-Host -Prompt ‘Input PC Name’
$computers | foreach {
Dir C:users}
$size=(dir $_.FullName -recurse -force -ea silentlycontinue | Measure-Object ‘length’ -sum -Maximum).sum
write-host(“{0:n2}” -f ($size/1MB) +” MB”,$_.fullname)
$computers =Read-Host -Prompt ‘Input PC Name’
foreach ($computer in $computers) {
dir “\$computerC$users”}
$size=(dir $_.FullName -recurse -force -ea silentlycontinue | Measure-Object ‘length’ -sum -Maximum).sum
write-host(“{0:n2}” -f ($size/1MB) +” MB”,$_.fullname)
As a side note- unable to output to file
Out-File -output path “C:tempout.txt”
Out-File “C:tempout.txt”
>
Have google extensively, however unable to get similar (or other) to work)
Thank you in advance
You must be logged in to reply to this topic.
Find out more about our cookie policy here.