I’m trying to get the Manufacturer,Model,Serial Number and hostname from a list of computers in my domain. I was thinking to do this:
Get-ADComputer -Filter * -Properties Name | Select-Object Name | Export-Csv c:\working\computers.csv
That gets my working list of computers.
Then I would use:
Get-WmiObject -ComputerName (My .csv list of computers) -Class Win32_ComputerSystem -Properties (etc…)
My problem is doing the get-WmiObject process on each of the computers in my list.
I’m still Powershell novice so no complex scripting if possible. I’ll get to that eventually but for now, I want it as simple as possible.
Thank you!
try this
$computers = Get-ADComputer -Filter *
$computers | Export-Csv c:\working\computers.csv -NoTypeInformation
$results = foreach ($computer in $computers) {
$model = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$computer).OpenSubKey('HARDWARE\DESCRIPTION\System\BIOS').GetValue('SystemProductName')
$serial = (Get-WMIObject WIN32_SystemEnclosure -ComputerName $computer).SerialNumber
[pscustomobject]@{
ComputerName = $computer
Model = $model
Serial = $serial
}
}
$results | Export-Csv c:\working\computersinfo.csv -NoTypeInformation
Lots of red:
Exception calling “OpenRemoteBaseKey” with “2” argument(s): "The network path was not found.
"
At line:6 char:5
$model = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$co ...
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException
Get-WMIObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:7 char:16
$computers = ((Get-ADComputer -Filter *).Name -split "`n")
$sysinfo = foreach ($computer in $computers){
$sysobj1 = Get-WmiObject -Class win32_computersystem -ComputerName $computer
$sysobj2 = Get-WmiObject -Class Win32_systemenclosure -ComputerName $computer
[PSCustomObject]@{
Manufacturer = $sysobj1.manufacturer
Model = $sysobj1.model
SerialNumber = $sysobj2.serialnumber
HostName = $sysobj1.Name}
}
$sysinfo | export-csv .\sysinfo.csv -NoTypeInformation
I have a .csv file with 1137 lines of :
LENOVO 20BWS4FH00 PC07X2V9 'MYCOMPUTERNAME"
Which is my local computer
I need that for all the other computers too.
Sorry, that didn’t work either. I have run
gwmi -class win32_computersystem -computername ‘computername’
on several random hosts in our network and i get the info. It seems to have something to do with getting the list of names into the ComputerName property.
Here is the error I get:
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:4 char:16
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:5 char:16
you may need to use enable-psremoting on those computers then retry
If I needed to enable psremoting would I be able to run
Get-WmiObject -Class win32_computersystem -ComputerName
on individual computers?
try this using the function here
# Requires the PSRemoteRegistry module
# https://psremoteregistry.codeplex.com/
# https://blogs.technet.microsoft.com/heyscriptingguy/2006/06/21/how-can-i-use-windows-powershell-to-start-a-service-on-a-remote-computer/
# https://gallery.technet.microsoft.com/scriptcenter/Enable-PSRemoting-Remotely-6cedfcb0
function Enable-PSRemoting {
param (
[string[]]$Computers = (Read-Host 'Enter computer name'),
[switch]$ShowSkipped
)
if (!$Computers) {Throw 'No computer name entered.'}
$services = 'WinRM', 'RasAuto', 'RpcLocator', 'RemoteRegistry', 'RemoteAccess'
$skipped = @()
Import-Module PSRemoteRegistry
foreach ($computer in $Computers) {
This file has been truncated. show original
you may need this to get that function to work.
https://psremoteregistry.codeplex.com/
$computer = 'Workstation1'
enable-psremoting $computer
gwmi win32_computersystem -comp $computer
My apologies Anthony. Your script does work. Apparently a large number of the computers in my list are not one line.
Thank you very much for your assistance!