Need help to get file count from remote server directory using powershell

  • Hi, I need help to get file count from the directory "T:/System Volume information" from a remoter server

    I'm trying to run below PSEXEC command but its failing.

    psexec \\MYSERVER28 -S cmd DIR "T:\System Volume Information" /b/a-d | find /v /c "::"

    how can i achieve the file count on remote server.

  • If remote command execution is open between the servers or computers you can use Invoke-Command:

    Invoke-Command -Computer MYSERVER28 {(dir 'T:\System Volume Information').Count}

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

  • Thanks a lot Shwan. this little command works like charm. One last think. how can i delete files remotely in the same remote directory path?

  • If you are not concerned with it and just to delete it all, just pipe that dir command to "Remove-Item -force".

    If you need only certain files deleted then just add addition code in the brackets using the dir to just get those files you want, and then pipe to the remove command.

    So if I only want to delete text files:

    Dir *.txt | remove-item

    You can add in "-what if" to verify what would get deleted.

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

  • Wow !! thanks for the tip. works like charm. thanks a milion.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply