0

I need to create a powershell script you can double-click on (64-bit computer) and it will output to a .txt file in the same location as the powershell script to generate information on:

  • Computer name/model/serial no.
  • C drive size/available disk space on the C drive
  • Which version operating system the computer is running
  • Who is currently logged onto the computer

So far (but it's not quite working) I've got:

$computerSystem = get-wmiobject Win32_ComputerSystem
$computerOS = get-wmiobject Win32_OperatingSystem
$computerHDD = Get-WmiObject Win32_LogicalDisk -Filter drivetype=3

$txtObject = New-Object PSObject -property @{
    'PCName' = $computerSystem.Name
    'Model' = $computerSystem.Model
    'SerialNumber' = $computerBIOS.SerialNumber
    'HDDSize' = "{0:N2}" -f ($computerHDD.Size/1GB)
    'HDDFree' = "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size)
    'OS' = $computerOS.caption
    'SP' = $computerOS.ServicePackMajorVersion
    'User' = $computerSystem.UserName
    } 

$txtObject | Select PCName, Model, SerialNumber, HDDSize, HDDFree, OS, SP, User | Get-Process | Out-File 'system-info.txt' -NoTypeInformation -Append
0

1 Answer 1

1

$PSScriptRoot = current location where your script is launched, so if you specify it in the save path like Out-File "$PSScriptRoot\system-info.txt", it will be saved at the same location as the script

Get-Process can't be used at this position

NoTypeInformation does not exist as a parameter of Out-File

$computerSystem = get-wmiobject Win32_ComputerSystem
$computerOS = get-wmiobject Win32_OperatingSystem
$computerHDD = Get-WmiObject Win32_LogicalDisk -Filter drivetype=3

$txtObject = New-Object PSObject -property @{
    'PCName' = $computerSystem.Name
    'Model' = $computerSystem.Model
    'SerialNumber' = $computerBIOS.SerialNumber
    'HDDSize' = "{0:N2}" -f ($computerHDD.Size/1GB)
    'HDDFree' = "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size)
    'OS' = $computerOS.caption
    'SP' = $computerOS.ServicePackMajorVersion
    'User' = $computerSystem.UserName
    } 

$txtObject | Select-Object PCName, Model, SerialNumber, HDDSize, HDDFree, OS, SP, User | Out-File "$PSScriptRoot\system-info.txt" -Append
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.