Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Need of powershell script(Sorry new to PS and need help fast)

Closed Thread
 
Thread Tools Display Modes
Old 01-28-2008   #1 (permalink)
Jim
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...
Old 01-28-2008   #2 (permalink)
Shay Levi
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
Quote:

> 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...
>

Old 01-28-2008   #3 (permalink)
Jim
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:
Quote:

>
>
>
> 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
>
Quote:

> > 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...
> >
>
>
>
Old 01-28-2008   #4 (permalink)
Marco Shaw [MVP]
Guest


 

Re: Need of powershell script(Sorry new to PS and need help fast)

Jim wrote:
Quote:

> Hi Shay,
>
> Thanks- Good point.. Is it possible to get the currently logged on user (if
> present) or the last logged on user?
get-wmiobject -computer . win32_computersystem|select-object username

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
Old 01-28-2008   #5 (permalink)
Darren Mar-Elia
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
Quote:

> Jim wrote:
Quote:

>> Hi Shay,
>>
>> Thanks- Good point.. Is it possible to get the currently logged on user
>> (if present) or the last logged on user?
>
> get-wmiobject -computer . win32_computersystem|select-object username
>
> 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
Old 01-29-2008   #6 (permalink)
Jim
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:
Quote:

> Jim wrote:
Quote:

> > Hi Shay,
> >
> > Thanks- Good point.. Is it possible to get the currently logged on user (if
> > present) or the last logged on user?
>
> get-wmiobject -computer . win32_computersystem|select-object username
>
> 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
>
Old 01-29-2008   #7 (permalink)
Shay Levi
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
Quote:

> 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:
>
Quote:

>> Jim wrote:
>>
Quote:

>>> Hi Shay,
>>>
>>> Thanks- Good point.. Is it possible to get the currently logged on
>>> user (if present) or the last logged on user?
>>>
>> get-wmiobject -computer . win32_computersystem|select-object username
>>
>> 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

Old 01-29-2008   #8 (permalink)
Jim
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:
Quote:

>
> 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
>
Quote:

> > 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:
> >
Quote:

> >> Jim wrote:
> >>
> >>> Hi Shay,
> >>>
> >>> Thanks- Good point.. Is it possible to get the currently logged on
> >>> user (if present) or the last logged on user?
> >>>
> >> get-wmiobject -computer . win32_computersystem|select-object username
> >>
> >> 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
>
>
>
Closed Thread

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








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50