ForEach – Remote Enumeration

Home Forums Scripting PowerShell ForEach – Remote Enumeration

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    LIC
    Member
    #167697

    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)



    This returns remote directories – with no size

    $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

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.