Mark Minasi's Tech Forum
Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
JimiV

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 61
Reply with quote  #1 
Hi All,

I've looked and looked and can't find a way to do this in PS.  What I want to do is, get list of a particular remote computer drives. Local and Mapped to the network of the logged in user.  Output to just the screen is fine.  Ideally it would like like this:

C: Local Hard drive
S: Network drive   \\Servername\sharename
X: Network drive   \\Servername\sharename


I'm more than happy to supply the computer name by entering it into the script or any other way.  I just want to be able to put in a workstation name and get the equivielent of running NET USE from the cmd on that workstation.


Thanks!!!!
Jimi
0
cj_berlin

Avatar / Picture

Senior Member
Registered:
Posts: 431
Reply with quote  #2 
Hi,

local drives are easy:


Get-WMIObject Win32_Volume -ComputerName <remote-computer> | Select Name


or, since we are supposed to be using CIM going forward,


Get-CIMInstance Win32_Volume -ComputerName <remote-computer> | Select Name


Mapped drives for another user's session... Your best bet is probably HKCU:\Network which means subtrees of HKU. In my experience though, only drives mapped as persistent will appear there.

__________________
Evgenij Smirnov

MVP Cloud & Datacenter Management
My personal blog (German): http://www.it-pro-berlin.de/
My stuff on PSGallery: https://www.powershellgallery.com/profiles/it-pro-berlin.de/
0
JimiV

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 61
Reply with quote  #3 
Yeah, Local drives are easy.  It's the damn network drives the logged on user has, is what I need. Grrrrr
0
cj_berlin

Avatar / Picture

Senior Member
Registered:
Posts: 431
Reply with quote  #4 
OK, quick and very dirty:

$sb = [scriptblock]{
    New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS
    foreach ($ureg in (Get-ChildItem 'HKU:' | where {$_.Name -match '^.*\\S\-1\-5\-.+\-\d+\-\d+$'})) {
        foreach ($drv in (Get-ChildItem "HKU:\$($ureg.PSChildName)\Network")) {
            "$($drv.PSChildName): --> $($drv | Get-ItemPropertyValue -Name 'RemotePath')"
        }
    }
}
Invoke-Command -ComputerName <remote-computer>  -ScriptBlock $sb 


Gotta have local admin rights on the remote machines, of course.

__________________
Evgenij Smirnov

MVP Cloud & Datacenter Management
My personal blog (German): http://www.it-pro-berlin.de/
My stuff on PSGallery: https://www.powershellgallery.com/profiles/it-pro-berlin.de/
0
JimiV

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 61
Reply with quote  #5 
Thanks so much!!!  That gives me what I need.   I really appreciate it!
0
jsclmedave

Administrator
Registered:
Posts: 506
Reply with quote  #6 
Quote:
Originally Posted by cj_berlin
OK, quick and very dirty:
 $sb = [scriptblock]{ New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS foreach ($ureg in (Get-ChildItem 'HKU:' | where {$_.Name -match '^.*\\S\-1\-5\-.+\-\d+\-\d+$'})) { foreach ($drv in (Get-ChildItem "HKU:\$($ureg.PSChildName)\Network")) { "$($drv.PSChildName): --> $($drv | Get-ItemPropertyValue -Name 'RemotePath')" } } } Invoke-Command -ComputerName -ScriptBlock $sb 

Gotta have local admin rights on the remote machines, of course.



NICE!!

__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.