Asked by:
PowerShell Script to Add local computer description to AD via SCCM TS

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 {
param($computer)
Import-module ActiveDirectory
Set-ADComputer $Computer -Description "$Desc"
} -Args $computer
Remove-PSSession $remotesessionThanks,
Scott
- Edited by ScottEvans2013 Thursday, November 14, 2019 5:09 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
-
-
-
-
$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
-
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
- Edited by ScottEvans2013 Friday, November 15, 2019 2:25 PM
-
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") $dirEntry.SetInfo()
-- Bill Stewart [Bill_Stewart]
- Proposed as answer by Bill_StewartModerator Tuesday, November 19, 2019 7:20 PM