Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » PowerGUI User Discussions

Thread: Script help. Adding computer name to output

This question is answered.


Permlink Replies: 12 - Pages: 1 - Last Post: Nov 30, 2009 8:10 AM by: Jason Benway
Jason Benway


Posts: 18
Registered: 7/21/09
Script help. Adding computer name to output
Posted: Nov 24, 2009 6:14 PM
 
  Click to reply to this thread Reply

I'm trying to read in a list of computers and output the mapped drives.
I have it working, but the output doesn't like the computer name. Here's what I have.

gc c:\jb.txt |% {gwmi -computer $_ -query "Select * From Win32_LogicalDisk Where DriveType = 4" } | ft computer,DeviceID, ProviderName





seaJhawk


Posts: 436
Registered: 12/15/08
Re: Script help. Adding computer name to output
Posted: Nov 24, 2009 8:26 PM   in response to: Jason Benway
 
  Click to reply to this thread Reply

Hi Jason,
Can you provide us the first two lines of jb.txt?

/chris


Shay Levy


Posts: 1,346
Registered: 1/31/08
Re: Script help. Adding computer name to output
Posted: Nov 25, 2009 12:53 AM   in response to: Jason Benway
Answered
  Click to reply to this thread Reply

Format-Table cannot access members of Get-Content however, you can get the machine name from the WMI output, replace 'computer' with 'SystemName':

gc c:\jb.txt | % {gwmi -computer $_ -query "Select * From Win32_LogicalDisk Where DriveType = 4" } | ft SystemName,DeviceID, ProviderName


Message was edited by: Shay Levy

Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
Jason Benway


Posts: 18
Registered: 7/21/09
Re: Script help. Adding computer name to output
Posted: Nov 25, 2009 7:47 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply

awesome, thank you.

where do I findout what other fields/values I could grab with 'gwmi -computer $_ -query "Select * From Win32_LogicalDisk Where DriveType = 4" ' ?

When I manually run gwmi -query "select * from win32_logicaldisk where drivetype = 4" systemname is not in the output or is it format-table that gives me the additional fields/values?

thanks,jb



seaJhawk


Posts: 436
Registered: 12/15/08
Re: Script help. Adding computer name to output
Posted: Nov 25, 2009 8:03 AM   in response to: Jason Benway
Helpful
  Click to reply to this thread Reply

Try these:

gwmi -query "select * from win32_logicaldisk where drivetype = 4" | get-member


gwmi -query "select * from win32_logicaldisk where drivetype = 4" | format-list *

-Chris


Jason Benway


Posts: 18
Registered: 7/21/09
Re: Script help. Adding computer name to output
Posted: Nov 25, 2009 8:11 AM   in response to: seaJhawk
 
  Click to reply to this thread Reply

Thanks, I've updated the script so I can output it to a csv.
now I have
gc c:\jb.txt | % {gwmi -computer $_ -query "Select * From Win32_LogicalDisk Where DriveType = 4" } | Select-Object SystemName,DeviceID, ProviderName  | Export-Csv c:\drivelist.csv -NoTypeInformation

But the strange thing is this only seems to work on my computer. I have three computer names in the jb.txt file (mycomputer,computer in a different domain, computer in same domain) I can ping all by hostname, I know I have permissions on the computer in the current domain.

the funny thing is I got get an error. I can run it manually from a PS commandline and it just returns to the prompt with no results and no errors.

Running
gwmi -computer othercomputer -query "Select * From Win32_LogicalDisk Where DriveType = 4"

returns nothing and I know they have drives mapped



Jason Benway


Posts: 18
Registered: 7/21/09
Re: Script help. Adding computer name to output
Posted: Nov 25, 2009 8:18 AM   in response to: Jason Benway
 
  Click to reply to this thread Reply

I figured out why I'm not getting data on the remote computers.

I'm looking for DriveType = 4 which is a list of their mapped drives.

The script doesn't seem to be pulling wmi information for the currently logged in user.

If I remove the where part of my select statment I get information about the c: drive of the other two computers. But I need information on the mapped drives of the logged in user.

Any way to get that?

thanks,jb



Shay Levy


Posts: 1,346
Registered: 1/31/08
Re: Script help. Adding computer name to output
Posted: Nov 25, 2009 8:45 AM   in response to: Jason Benway
 
  Click to reply to this thread Reply

See if this class helps:

Win32_MappedLogicalDisk


Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
Jason Benway


Posts: 18
Registered: 7/21/09
Re: Script help. Adding computer name to output
Posted: Nov 25, 2009 10:36 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply

same results. nothing returned for a remote computer.
Looks like I may have to try to do this via logon script :-(



seaJhawk


Posts: 436
Registered: 12/15/08
Re: Script help. Adding computer name to output
Posted: Nov 25, 2009 1:49 PM   in response to: Jason Benway
 
  Click to reply to this thread Reply

Jason,
Keep trying with the Win32_MappedLogicalDisk class. I've had success using it.

-Chris


Jason Benway


Posts: 18
Registered: 7/21/09
Re: Script help. Adding computer name to output
Posted: Nov 25, 2009 2:47 PM   in response to: seaJhawk
 
  Click to reply to this thread Reply

are you saying you've successfully pulled mapped drives from remote computers with other user logged in?



Shay Levy


Posts: 1,346
Registered: 1/31/08
Re: Script help. Adding computer name to output
Posted: Nov 26, 2009 2:57 AM   in response to: Jason Benway
 
  Click to reply to this thread Reply

Check the 'Remarks' section at the bottom of this page:

http://msdn.microsoft.com/en-us/library/aa394194(VS.85).aspx




Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
Jason Benway


Posts: 18
Registered: 7/21/09
Re: Script help. Adding computer name to output
Posted: Nov 30, 2009 8:10 AM   in response to: Shay Levy
 
  Click to reply to this thread Reply

These are XP workstations so I changed the local policy to referenced in the link you posted to "administrators group" and rebooted the computer. but I'm still not getting the mapped drives. I'm even logged in as the same user has I'm running the PS from the other computer.

Thank you everyone for your help. I think I'm going to put my time into looking at a way to do this via logon script.

jb



Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums