1 | initial version |
Here's an example PowerShell script that can extract serial number and model information from a list of computers, and export it to an Excel file:
# Define the list of computers
$computers = Get-Content -Path "C:\Users\UserName\Desktop\ComputerList.txt"
# Create an empty array to store the computer information
$computerInfo = @()
# Loop through each computer and extract the information
foreach ($computer in $computers) {
# Use the Get-WmiObject cmdlet to get the serial number and model
$serialNumber = Get-WmiObject -Class Win32_Bios -ComputerName $computer | Select-Object -ExpandProperty SerialNumber
$model = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer | Select-Object -ExpandProperty Model
# Add the computer information to the array
$computerInfo += [PSCustomObject]@{
"ComputerName" = $computer
"SerialNumber" = $serialNumber
"Model" = $model
}
}
# Export the computer information to an Excel file
$computerInfo | Export-Excel -Path "C:\Users\UserName\Desktop\ComputerInfo.xlsx" -WorksheetName "ComputerInfo" -AutoSize
To run this script remotely, you will need to have the appropriate permissions and access to the remote computers. You can use the -Credential
parameter with the Get-WmiObject
cmdlet to specify the credentials to use for the remote connection. For example:
$credential = Get-Credential
$serialNumber = Get-WmiObject -Class Win32_Bios -ComputerName $computer -Credential $credential | Select-Object -ExpandProperty SerialNumber
This will prompt you for the username and password to use for the remote connection. Alternatively, you can store the credentials in a secure string and use the ConvertTo-SecureString
and Get-Credential
cmdlets to create the credential object.