none
Set-ADComputer multiple values in -Description RRS feed

  • Question

  • Hello,

    I´m an beginner in Powershell and I would like to figure out how I can auto fill in the description for AD Computersobjects.
    What I´m after is the model of the computer and serialnumber.

    I can get the script work when only using one variable in -Description, but I want to have both of them.

    The script I have so far is:

    $computers = Get-ADComputer -Filter * -SearchBase "Specified path"

    foreach ($computer in $computers) 
    {
    $computerName = Get-WmiObject Win32_ComputerSystem
    $ComputerSerial = Get-WmiObject Win32_bios
    Set-ADComputer -Identity $Computername.Name  -Description $computername.Model;$ComputerSerial.SerialNumber

    Best regards, Mikael

    Monday, December 22, 2014 1:58 PM

Answers

  • Assuming you're wanting the details from the remote machines - 

    foreach ($computer in $computers) 
    {
    $model = (Get-WmiObject Win32_ComputerSystem -ComputerName $Computer.name).Model
    $ComputerSerial = (Get-WmiObject Win32_bios -ComputerName $Computer.name).SerialNumber
    Set-ADComputer -Identity $Computer.name  -Description "$Model ; $ComputerSerial"
    } 

    Monday, December 22, 2014 4:01 PM

All replies

  • $serial=(Get-WmiObject Win32_bios).SerialNumber
    $description="$env:COMPUTERNAME ; $serial"

    ¯\_(ツ)_/¯

    Monday, December 22, 2014 3:43 PM
  • Assuming you're wanting the details from the remote machines - 

    foreach ($computer in $computers) 
    {
    $model = (Get-WmiObject Win32_ComputerSystem -ComputerName $Computer.name).Model
    $ComputerSerial = (Get-WmiObject Win32_bios -ComputerName $Computer.name).SerialNumber
    Set-ADComputer -Identity $Computer.name  -Description "$Model ; $ComputerSerial"
    } 

    Monday, December 22, 2014 4:01 PM
  • I do something similar in our domain.  However, in my Description field, we keep many values, and it is easy to change one computer's Description field without changing the remainders. Just importing them and parsing them by the delimiters ( ";"  in Jrv's example) assumes that all computer Description fields will always have the correct number and orders of fields. In my example, you would just use ConvertFrom-JSON to change it back from a text string to an object.

    $description = @{} $description.Name = $env:COMPUTERNAME $description.Serial = (Get-WmiObject Win32_bios).SerialNumber $description.AsOf = (Get-date).Date $descriptionEntry = $description | ConvertTo-Json -Compress Set-ADComputer -Identity $Computername.Name  -Description $descriptionEntry

    ConvertFrom-Json -InputObject $descriptionEntry




    Monday, December 22, 2014 9:53 PM