Jean-Jacques CELMA
asked on
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\Harddi sk0\Partit ion1
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
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\Harddi
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
ASKER
Thks Guy,
But I would like to use the read-host value.
When I add it, it give me nothing
Thks
JJC
But I would like to use the read-host value.
When I add it, it give me nothing
Thks
JJC
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?
Secondly, are you running this as a .ps1 script?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER
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-WMIOB JECT win32_bios -computername $computer).SerialNumber}}
$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-WMIOB
Hi there,
Glad you've got it working !
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 !
does this help?
Open in new window