none
Retrieve System Information RRS feed

  • General discussion

  • I am attempting (noob) to write a script that writes system info to a flat file and am having difficulty with retrieving the IPv4 address and a custom registry value... Any assistance would be GREATLY appreciated. Thank you

     
    $computerSystem = Get-CimInstance CIM_ComputerSystem
    $computerBIOS = Get-CimInstance CIM_BIOSElement
    $computerOS = Get-CimInstance CIM_OperatingSystem
    $computerCPU = Get-CimInstance CIM_Processor
    $computerHDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
    $NetItems = Get-WmiObject Win32_NetworkAdapterConfiguration | where{$_.IPEnabled -eq "True" -and $_.DNSHostName -ne $NULL}
    $ImageVersion = Get-ItemPropertyValue HKLM:\Software\TrueBlue\Laptop_FR\Task_Sequence_Name 
    Clear-Host
    
    Write-Host "System Information for: " $computerSystem.Name -BackgroundColor DarkCyan
    "Manufacturer: " + $computerSystem.Manufacturer
    "Model: " + $computerSystem.Model
    "Serial Number: " + $computerBIOS.SerialNumber
    "CPU: " + $computerCPU.Name
    "HDD Capacity: "  + "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
    "HDD Space: " + "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + " Free (" + "{0:N2}" -f ($computerHDD.FreeSpace/1GB) + "GB)"
    "RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
    "Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
    "User logged In: " + $computerSystem.UserName
    "Last Reboot: " + $computerOS.LastBootUpTime
    "IPv4 Adress:" + $NetItems.IPv4Address
    "Image Version:" + $ImageVersion.ImageVersion


    DHeinz

    • Changed type Bill_Stewart Friday, November 2, 2018 9:58 PM
    • Moved by Bill_Stewart Friday, November 2, 2018 9:59 PM This is not "debug/fix/rewrite my script for me" forum
    Tuesday, July 10, 2018 3:05 PM

All replies

  • Help out-file -online
    help append-file -online
    help redirection

    \_(ツ)_/

    Tuesday, July 10, 2018 3:38 PM
  • Write-Host cannot be redirected to a file.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, July 10, 2018 4:39 PM
  • Like Bill said you cannot create a file from the output of write-host. 

    I can help you with one of your concerns.  The call to

    Win32_NetworkAdapterConfiguration

    Does not return an IPV4Address property.  It only returns an IPAddress property that is an array if you have both IPV6 and IPV4 enabled.  If so then change the display of the IP address field as in the following.  It will return the first element of the array which will be the IPV4 address.  If you only use IPV4 then take out the [0] and just display the IPAddress property.

    I do not have the Reg key that you are looking for on my computer but if you leave the clear-host commented you may be able to see if you are getting an error when looking for the key.

    $computerSystem = Get-CimInstance CIM_ComputerSystem
    $computerBIOS
    = Get-CimInstance CIM_BIOSElement
    $computerOS
    = Get-CimInstance CIM_OperatingSystem
    $computerCPU
    = Get-CimInstance CIM_Processor
    $computerHDD
    = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
    $NetItems
    = Get-WmiObject Win32_NetworkAdapterConfiguration | where{$_.IPEnabled -eq "True" -and $_.DNSHostName -ne $NULL}
    $ImageVersion
    = Get-ItemPropertyValue HKLM:\Software\TrueBlue\Laptop_FR\Task_Sequence_Name
    #Clear-Host

    Write-Host "System Information for: " $computerSystem.Name -BackgroundColor DarkCyan
    "Manufacturer: " + $computerSystem.Manufacturer
    "Model: " + $computerSystem.Model
    "Serial Number: " + $computerBIOS.SerialNumber
    "CPU: " + $computerCPU.Name
    "HDD Capacity: "  + "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
    "HDD Space: " + "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + " Free (" + "{0:N2}" -f ($computerHDD.FreeSpace/1GB) + "GB)"
    "RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
    "Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
    "User logged In: " + $computerSystem.UserName
    "Last Reboot: " + $computerOS.LastBootUpTime
    "IPv4 Adress:" + $NetItems.IPAddress[0]
    "Image Version:" + $ImageVersion.ImageVersion

    Tuesday, July 10, 2018 7:21 PM