![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Need of powershell script(Sorry new to PS and need help fast) I need a PS script to do the following: Run on remote computers using a list. txt or xls. Collect the following: Computer Name - SerialNumber - Username Export results into an xls file. Thanks for any help provided... |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Need of powershell script(Sorry new to PS and need help fast) get-wmiobject win32_bios -computer (get-content .\computers.txt) | select __SERVER,SerialNumber | export-csv .\computers.csv What do you mean by username, the current logged on user? What if no one is logged in? ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Need of powershell script(Sorry new to PS and need help fast) Hi Shay, Thanks- Good point.. Is it possible to get the currently logged on user (if present) or the last logged on user? "Shay Levi" wrote:
| ||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||
| Guest | Re: Need of powershell script(Sorry new to PS and need help fast) Jim wrote:
MSDN says: "UserName Data type: string Access type: Read-only Name of a user that is logged on currently. This property must have a value. In a terminal services session, UserName returns the name of the user that is logged on to the console—not the user logged on during the terminal service session." The easiest I could come up with. Another solution seemed to be having to read a registry value to get the last logged on user. I'll keep digging or someone will beat me to it. -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com | ||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Need of powershell script(Sorry new to PS and need help fast) The UserName property in Win32_ComputerSystem is the most reliable in my experience. There's no place in the registry that I know of that reliably returns the last user who logged on. The information is held there (can't remember the key right now) but can be removed at the administrator's choice. Also, I logged an issue during testing of Server 2008 where the username property was not populated in Win32_ComputerSystem when a user was logged on, so that behavior might have changed. Darren -- "Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com> wrote in message news:%23otmqciYIHA.4440@xxxxxx
| ||||||||||||||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Need of powershell script(Sorry new to PS and need help fast) Hi Marco this may work for me how do I put Shay line together with your line in one ps script so that I get the output to read. Username, Computer name, Serial Number" Thanks! "Marco Shaw [MVP]" wrote:
| ||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Need of powershell script(Sorry new to PS and need help fast) get-content .\computers.txt | foreach { $sn = gwmi -q "select serialNumber from win32_bios" -computer $_ $computerSystem = gwmi -q "select name,userName from Win32_ComputerSystem" -computer $_ $obj = new-object psobject add-member -inp $obj NoteProperty "Name" $computerSystem.name add-member -inp $obj NoteProperty "Serial Number" $sn.serialNumber add-member -inp $obj NoteProperty "User Name" $computerSystem.userName $obj } | export-csv .\computers.csv -noType ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||||||||||||||||||||||||||
| | #8 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Need of powershell script(Sorry new to PS and need help fast) Perfect. Thanks everyone now its time for me to read up and/or take a powershell class. :-) "Shay Levi" wrote:
| ||||||||||||||||||||||||||||||||||||
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Powershell script help | Tboz | PowerShell | 3 | 08-01-2008 08:58 AM |
| Script runs too fast | Shay Levi | PowerShell | 2 | 02-25-2008 03:00 PM |
| when run powershell script as windows service ,powershell fail | powershell fail on winodws 2008 | PowerShell | 6 | 01-15-2008 03:20 PM |
| Has anyone used Powershell to script WSUS? | Bob Landau | PowerShell | 4 | 12-10-2007 02:01 PM |
| PowerShell ESX Patch Script | dm3281 | PowerShell | 3 | 10-17-2007 10:35 PM |