Powershell scripting : GET-WMIOBJECT

Dear All,

From my windows 7 entreprise, I launched this powershell script.

Get-credential
$computer= read-host 'computer name?'
cls
write $computer
(GET-WMIOBJECT win32_operatingsystem -computername $computer).Name;
(GET-WMIOBJECT win32_operatingsystem -computername $computer).OSArchitecture;
(GET-WMIOBJECT win32_bios -computername $computer).SerialNumber;

The result I got is :

modtestjj
Microsoft Windows 7 Entreprise |C:\windows|\Device\Harddisk0\Partition1
64 bits
PB58LNG

How can I get the result like this

ComputerName      OS version                      OS architecture      Serial number
modtestjj              Microsoft Windows 7         64 bits                           PB58LNG
celmajjAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy LidbetterCommented:
Hi,

does this help?

Get-WmiObject -Computername $Computer win32_operatingsystem | Select @{N="Computer Name";E={$_.PSComputerName}}, @{N="OS Version";E={$_.Caption}}, OSArchitecture, @{N="Serial";E={(GET-WMIOBJECT win32_bios -computername $computer).SerialNumber}}

Open in new window

0
celmajjAuthor Commented:
Thks Guy,

But I would like to use the read-host value.
When I add it, it give me nothing

Thks

JJC
0
Guy LidbetterCommented:
A couple of things, what are you doing with the credential? You are asking for it but not doing anything with it.

Secondly, are you running this as a .ps1 script?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Guy LidbetterCommented:
Here is the script using the provided credentials... save it as a .ps1 and just run it.

$Cred = Get-credential
$computer= read-host 'computer name?'
cls
write $computer
Get-WmiObject -Computername $Computer win32_operatingsystem -Credential $Cred | Select @{N="Computer Name";E={$_.PSComputerName}}, @{N="OS Version";E={$_.Caption}}, OSArchitecture, @{N="Serial";E={(GET-WMIOBJECT win32_bios -computername $computer -Credential $Cred).SerialNumber}}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
celmajjAuthor Commented:
I am running this as a ps1
If I am working from a computer that does not have admin rights I have to log off then log back in with admin credentials to run the script, correct?.
So, that the reason why I input a log in windows

JJC
0
celmajjAuthor Commented:
I slightely modified your script and get it working like that :

 $Cred = Get-credential
$computer= read-host 'computer name?'
cls
Get-WmiObject -Computername $Computer win32_operatingsystem | Select @{N="Computer Name";E={$Computer}}, @{N="OS Version";E={$_.Caption}}, OSArchitecture, @{N="Serial";E={(GET-WMIOBJECT win32_bios -computername $computer).SerialNumber}}
0
Guy LidbetterCommented:
Hi there,

If I am working from a computer that does not have admin rights I have to log off then log back in with admin credentials to run the script, correct?.
No, you can run the script from anywhere, when it asks for account details put in the admin account.

Glad you've got it working !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.