none
Converting this batch file to execute remotely RRS feed

  • Question

  • Hi everyone,

    I need to collect the mapped drives for the logged in user on each machine remotely. 

    This is a hit or miss: https://social.technet.microsoft.com/Forums/windows/en-US/b09719d1-cf57-425b-b3e4-2933c77c0663/firewall-is-off-but-i-cant-pull-wmiobject?forum=w7itpronetworking#b09719d1-cf57-425b-b3e4-2933c77c0663

    This script works wonderful at the local level: 

    @echo off
    setlocal
    set ListFile=EE28961982.csv
    (
      for /f "skip=2 tokens=1-4 delims=," %%A in ('wmic netuse get localname^,remotename^,username /Format:csv') do (
        echo %%A,%username%,%%B,%%C,%%D
      )
    ) > "%ListFile%"

    My question is: How can I convert his script so that I can run it successfully on a remote computer. 

    I also tried to stick it to the man by running this script as a logon script but apparently it only works if its ran on the machine locally. So i've used software to run the batch file living on the desktop of the remote computer in question and that still fails. 

    Any assistance would be great. 

    Thanks!


    • Edited by SilentCow Wednesday, September 14, 2016 4:15 PM
    Wednesday, September 14, 2016 4:14 PM

Answers

  • We are switching mapped drive locations from one server to another. So I need to know what to disconnect and connect.

    You don't need to read drive mappings remotely. Just configure needed drive mappings using Group Policy. You don't need a script.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 14, 2016 8:51 PM
    Moderator

All replies

  • You can't.  The drives are only mapped to the user and only when they are logged in.  There is not command to do this.


    \_(ツ)_/

    Wednesday, September 14, 2016 4:29 PM
  • I need to collect the mapped drives for the logged in user on each machine remotely.

    Why?


    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 14, 2016 4:51 PM
    Moderator
  • We are switching mapped drive locations from one server to another. So I need to know what to disconnect and connect. 

    This is the closest I've come to accomplishing that  Get-WmiObject-ClassWin32_MappedLogicalDisk -computer <computer name>|selectName,ProviderName

    Problem is it doesnt work on all computers. Even If I turn off all the firewalls and security software on the planet for it.

    Wednesday, September 14, 2016 5:05 PM
  • The way we do that is to set Group Policy to map the drives.  It will remove old mappings for the same drive letter.

    You could also dump this to a file in a logon script.

    You cannot get remote users drives without trash their sessions.  You cannot load the registry when a user is logged in.

    You could use a logon script that scans the users drives at logon and changes them.

    There is no other way.


    \_(ツ)_/

    Wednesday, September 14, 2016 5:45 PM
  • We are switching mapped drive locations from one server to another. So I need to know what to disconnect and connect.

    You don't need to read drive mappings remotely. Just configure needed drive mappings using Group Policy. You don't need a script.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 14, 2016 8:51 PM
    Moderator
  • Thank You all for your help. I found just what I needed and I am able to get remote users drives .

    We can close this thread.

    Monday, September 19, 2016 1:37 PM