Jump to content

Recommended Posts

Posted

Hey everyone,

Sorry if this is posted in the wrong area, not sure where to put it.

 

Trying to export some information from a powershell script into a csv but having a nightmare. Aim of script is to get pc name, serial number, make/model, ram & processor. Script runs fine but struggling to output it afterwards, wanting to avoid having to copy and paste it out at the end.

 

Keeps outputting this at the end of my script:

cmdlet Export-Csv at command pipeline position 1Supply values for the following parameters:InputObject:

 

---

 

This is the script im running

 

gwmi win32_bios -computername (PCNAME) | format-list serialnumber, PSComputerName, version gwmi win32_processor -computername (PCNAME)gwmi win32_physicalmemory -computername (PCNAME) | format-list capacityexport-csv -path (FILEPATH)

 

---

 

would appreciate any help i can get!

Posted (edited)
[/font][/color][color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$WksStationName[/color][/size][/font][font=Lucida Console][size=1][color=#696969] [/color][/size][/font][font=Lucida Console][size=1][color=#8b0000]'ADV-DC1'[/color][/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$Out [/color][/size][/font][font=Lucida Console][size=1][color=#696969]= [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]New-Object [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-TypeName [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]PSObject[/color][/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$WksStationName [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]%[/color][/size][/font][font=Lucida Console][size=1] {[/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$out [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]Add-Member [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyName [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]Computer_Name [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyValue [/color][/size][/font][font=Lucida Console][size=1][color=#a82d00]$_[/color][/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#0000ff]gwmi [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]win32_bios -ComputerName $_ [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]select [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]name[/color][/size][/font][font=Lucida Console][size=1][color=#696969],[/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]SerialNumber [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-OutVariable [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]BIOS[/color][/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$out [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]Add-Member [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyName [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]BIOS_Name [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyValue [/color][/size][/font][font=Lucida Console][size=1][color=#a82d00]$BIOS[/color][/size][/font][font=Lucida Console][size=1][color=#696969].[/color][/size][/font][font=Lucida Console][size=1]Name[/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$out [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]Add-Member [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyName [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]BIOS_Serial [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyValue [/color][/size][/font][font=Lucida Console][size=1][color=#a82d00]$BIOS[/color][/size][/font][font=Lucida Console][size=1][color=#696969].[/color][/size][/font][font=Lucida Console][size=1]SerialNumber[/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#0000ff]gwmi [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]win32_processor -ComputerName $_ [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]select [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]Caption[/color][/size][/font][font=Lucida Console][size=1][color=#696969],[/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]Manufacturer[/color][/size][/font][font=Lucida Console][size=1][color=#696969],[/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]Name [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-OutVariable [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]Processor[/color][/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$out [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]Add-Member [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyName [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]CPU_Caption [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyValue [/color][/size][/font][font=Lucida Console][size=1][color=#a82d00]$Processor[/color][/size][/font][font=Lucida Console][size=1][color=#696969].[/color][/size][/font][font=Lucida Console][size=1]Caption[/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$out [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]Add-Member [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyName [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]CPU_Manufacturer [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyValue [/color][/size][/font][font=Lucida Console][size=1][color=#a82d00]$Processor[/color][/size][/font][font=Lucida Console][size=1][color=#696969].[/color][/size][/font][font=Lucida Console][size=1]Manufacturer[/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$out [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]Add-Member [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyName [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]CPU_Name [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyValue [/color][/size][/font][font=Lucida Console][size=1][color=#a82d00]$Processor[/color][/size][/font][font=Lucida Console][size=1][color=#696969].[/color][/size][/font][font=Lucida Console][size=1]Name[/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#0000ff]gwmi [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]win32_physicalmemory -ComputerName $_ [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]select [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-ExpandProperty [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]Capacity [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-OutVariable [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]mem[/color][/size][/font][/font][/color]
[color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$out [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]Add-Member [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyName [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]Total_Mem [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NotePropertyValue [/color][/size][/font][font=Lucida Console][size=1][color=#a82d00]$mem[/color][/size][/font][font=Lucida Console][size=1][color=#696969][[/color][/size][/font][font=Lucida Console][size=1][color=#800080]0[/color][/size][/font][font=Lucida Console][size=1][color=#696969]][/color][/size][/font][/font][/color]
[font=Lucida Console][size=1][color=#000000][font=Lucida Console][size=1]}
[/size][/font][/color][/size][/font][color=#000000][font=Calibri][font=Lucida Console][size=1][color=#a82d00]$out [/color][/size][/font][font=Lucida Console][size=1][color=#696969]| [/color][/size][/font][font=Lucida Console][size=1][color=#0000ff]Export-Csv [/color][/size][/font][font=Lucida Console][size=1][color=#8a2be2]C:\LocalApp\PowerShell\Out\ComputerDetails.csv [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NoClobber [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-Append [/color][/size][/font][font=Lucida Console][size=1][color=#000080]-NoTypeInformation
[/color][/size][/font][/font][/color]

 

 

The above is a starter for 10, I can think of 10 things I would change right now to improve this.

Edited by HPlum78
Posted (edited)

Here's my attempt...

 

$Results = @()

$Computers = 'PC-001', 'PC-002'

$Computers | ForEach-Object {

   $BIOS = Get-WmiObject Win32_BIOS -ComputerName $_ | Select-Object PSComputerName, SerialNumber, Version
   $CPU  = Get-WmiObject Win32_Processor -ComputerName $_ | Select-Object Caption, Manufacturer, Name
   $RAM  = (Get-WmiObject Win32_ComputerSystem -ComputerName $_).TotalPhysicalMemory/1GB -as [int]

   $Specs = [PSCustomObject][Ordered]@{
       'Computer Name'    = $BIOS.PSComputerName
       'Serial Number'    = $BIOS.SerialNumber
       'BIOS Version'     = $BIOS.Version
       'CPU Caption'      = $CPU.Caption
       'CPU Manufacturer' = $CPU.Manufacturer.Replace('Genuine', '')
       'CPU Model'        = ($CPU.Name).Replace('Intel(R) ', '').Replace('(TM)', '')
       'Total RAM (GB)'   = $RAM
   }

   $Results += $Specs

}

$Results | Export-Csv -Path "$($env:USERPROFILE)\Desktop\ComputerDetails.csv" -NoClobber -Append -NoTypeInformation

Edited by Arthur
  • Thanks 1
Posted (edited)

I like Arthur's version, the only thing I might be tempted to add would be total RAM slots in the machine, and how many are used - for assistance in planning future upgrades ...

 

which would give :

 

$Results = @()
$Computers = 'PC-001', 'PC-002'

$Computers | ForEach-Object {

   $BIOS = Get-WmiObject Win32_BIOS -ComputerName $_ | Select-Object PSComputerName, SerialNumber, Version
   $CPU  = Get-WmiObject Win32_Processor -ComputerName $_ | Select-Object Caption, Manufacturer, Name
   $RAM  = (Get-WmiObject Win32_ComputerSystem -ComputerName $_).TotalPhysicalMemory/1GB -as [int]
   $colSlots = Get-WmiObject -class "Win32_PhysicalMemoryArray" -ComputerName $_ -namespace "root\CIMV2"
   $TotalSlots = $colSlots.MemoryDevices
   $colModules = Get-WMIObject -class "Win32_PhysicalMemory" -ComputerName $_ -namespace "root\CIMV2"
   $UsedSlots = 0
   foreach ($objItem in $colModules) {
   $UsedSlots = $UsedSlots + 1
   }

   $Specs = [PSCustomObject][Ordered]@{
       'Computer Name'    = $BIOS.PSComputerName
       'Serial Number'    = $BIOS.SerialNumber
       'BIOS Version'     = $BIOS.Version
       'CPU Caption'      = $CPU.Caption
       'CPU Manufacturer' = $CPU.Manufacturer.Replace('Genuine', '')
       'CPU Model'        = ($CPU.Name).Replace('Intel(R) ', '').Replace('(TM)', '')
       'Total RAM (GB)'   = $RAM
       'Total RAM slots'  = $TotalSlots
       'Used RAM slots'   = $UsedSlots
   }
   $Results += $Specs
}
$Results | Export-Csv -Path "$($env:USERPROFILE)\Desktop\ComputerDetails.csv" -NoClobber -Append -NoTypeInformation

Edited by MartinByard
  • Thanks 2
Posted

Yeah @Arthur has crafted a script with all the elegance of a ballerina where my munged version has all the finesse of a sailor on shore leave!

 

Good improvements and good call on the memory slots @MartinByard.

 

Like I said in my first reply the get-computerinfo looks like it is built in to ps 5.1 running on later OS's. So if you are win 10 you should probably leverage the built in cmdlet.

Posted (edited)

fwiw here my current abomination. it prompts for data as im manually running round and recording location info/main user etc

 


# New pcs get audit info v0.3
Add-Type -AssemblyName Microsoft.VisualBasic
# get pcs mac address(s)
$mac= Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"' | Select macAddress
# $mac
$mac2=$mac.macaddress
# get processor and pc name
$procinfo = Get-WmiObject Win32_Processor
$cpuname=$procinfo.Name
$pcname=$procinfo.SystemName
# get memory info/model/make
$pcinfo = Get-WmiObject Win32_ComputerSystem 
$maker=$pcinfo.Manufacturer
$model=$pcinfo.Model
$ram=$pcinfo.TotalPhysicalMemory/1024/1024/1024
$ram = "{0:N1}" -f $ram
#get serial no
$serial=Get-WmiObject Win32_BIOS
$serial2=$serial.SerialNumber
#hdd size and free in gb rounded to nearest whole no
$hdddata=Get-WmiObject Win32_LogicalDisk -Filter 'deviceid="c:"'
$freespace=$hdddata.FreeSpace/1024/1024/1024
$freespace = "{0:N0}" -f $freespace
$totalspace=$hdddata.size/1024/1024/1024
$totalspace = "{0:N0}" -f $totalspace
# get windows version
$os=Get-WmiObject Win32_OperatingSystem | select caption
$os2=$os.caption
#date-time
$now2= get-date -UFormat "%d/%m/%y"
#gets windows install date
$installdate=Get-CimInstance Win32_OperatingSystem | Select-Object  InstallDate | ForEach{ $_.InstallDate }
#asks operator for input
$location = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the computers location', 'Location', "ICT Suite")
$primaryuser = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the computers primary user (for pupil type shared)', 'Primary User', "Shared")
$dop = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the computers Date of purchase', 'date of purchase', "")
$invoiceno = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the invoice number if known', 'invoice number', "unknown")
$data = @()
$row = New-Object PSObject
$row | Add-Member -MemberType NoteProperty -Name "pcname" -Value $pcname
$row | Add-Member -MemberType NoteProperty -Name "macaddress" -Value $mac2
$row | Add-Member -MemberType NoteProperty -Name "Make" -Value $maker
$row | Add-Member -MemberType NoteProperty -Name "Model" -Value $model
$row | Add-Member -MemberType NoteProperty -Name "Processor" -Value $cpuname
$row | Add-Member -MemberType NoteProperty -Name "Ram in GB" -Value $ram
$row | Add-Member -MemberType NoteProperty -Name "HDD Space" -Value $totalspace
$row | Add-Member -MemberType NoteProperty -Name "Serial No" -Value $serial2
$row | Add-Member -MemberType NoteProperty -Name "Operating System" -Value $os2
$row | Add-Member -MemberType NoteProperty -Name "Data Gathered" -Value $now2
$row | Add-Member -MemberType NoteProperty -Name "Windows install date" -Value $installdate
$row | Add-Member -MemberType NoteProperty -Name "Computer location" -Value $location
$row | Add-Member -MemberType NoteProperty -Name "Computers primary user" -Value $primaryuser
$row | Add-Member -MemberType NoteProperty -Name "date of Purchase" -Value $dop
$row | Add-Member -MemberType NoteProperty -Name "Invoice number" -Value $invoiceno
$data += $row
$data | Export-Csv "$env:computername.csv" -NoTypeInformation


Edited by sted

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...