Ask Your Question
3

How can PowerShell be used to extract the serial number and model information from a list file and export it into an orderly Excel file, all done remotely?

asked 2023-01-07 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-10 19:00:00 +0000

bukephalos gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-01-07 11:00:00 +0000

Seen: 9 times

Last updated: Aug 10 '21