PowerShell Script to Add local computer description to AD via SCCM TS RRS feed

  • Question

  • Hi All, 

    I`m attempting to run a PowerShell script that will get the local computer description and add it to AD via an SCCM Task Sequence, here`s what I have and I think I`m pretty close but the description won`t add. 

    Any help would be gratefully appreciated;

    $Desc = (Get-WmiObject -Class Win32_OperatingSystem |Select Description).Description
    $computer = hostname
    $remotesession = New-PSSession -ComputerName Server
    Invoke-Command -Session $remotesession -ScriptBlock { 
        Import-module ActiveDirectory
                Set-ADComputer $Computer -Description "$Desc"
    } -Args $computer 
    Remove-PSSession $remotesession



    Thursday, November 14, 2019 5:07 PM

All replies

  • Why do you need to establish a remote session to update the computer description? If the current account has permission in AD, just set the description directly.

    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by jrv Thursday, November 14, 2019 7:00 PM
    Thursday, November 14, 2019 5:38 PM
  • The issue is likely that the AD CmdLets are no available on the local system.

    The new description is in the local session and needs to be passed to the remote session.

    You do not need a session to use Invoke once.


    Thursday, November 14, 2019 7:03 PM
  • Hi Bill, 

    Thanks for your reply.

    If you can let me know how to do this without importing Active Directory module I`ll happily give it a test.



    Friday, November 15, 2019 8:55 AM
  • Thanks Jrv, 

    So any advice on how to amend this script?



    Friday, November 15, 2019 8:55 AM
  • $desc = (Get-WmiObject -Class Win32_OperatingSystem).Description
    $computer = $env:COMPUTERNAME
    Invoke-command {Set-AdComputer $using:computer -Description $using:desc} -ComputerName Server1


    • Edited by jrv Friday, November 15, 2019 9:29 AM
    • Marked as answer by ScottEvans2013 Friday, November 15, 2019 9:39 AM
    • Unmarked as answer by ScottEvans2013 Friday, November 15, 2019 2:24 PM
    Friday, November 15, 2019 9:28 AM
  • Thank you very much. 

    I`ve just tested this via the SCCM TS and unfortunately it failed;

    "Invoke-command : The value of the using variable '$using:desc' cannot be retrieved because it has not been set in the local session."

        + CategoryInfo          : InvalidOperation: (:) [Invoke-Command], RuntimeException

        + FullyQualifiedErrorId : UsingVariableIsUndefined,Microsoft.PowerShell.Commands.InvokeCommandCommand

    Friday, November 15, 2019 9:39 AM
  • Yes, you can update a computer's description attribute without requiring the Active Directory module. Example:

    $dirEntry = [ADSI] "LDAP://CN=computername,OU=container,DC=fabrikam,DC=local"
    $dirEntry.Put("description","This is the description")

    -- Bill Stewart [Bill_Stewart]

    Friday, November 15, 2019 3:04 PM