SCCM 2012 / Add computer to AD Group during build

Welcome Forums General PowerShell Q&A SCCM 2012 / Add computer to AD Group during build

This topic contains 3 replies, has 3 voices, and was last updated by

2 years, 5 months ago.

  • Author
  • #11132

    Points: 0
    Rank: Member

    Setup: SCCM 2012, OSD Task Sequence, Windows 7 x64

    During the build after the computer is named, joined to domain, and processed whatever software it needs, I want to add the computer to an AD group for policies.

    Here's the AddComputer2ADGroup.ps1 I have today:
    $ComputerName = gc env:computername
    $GroupPath = "LDAP://CN=UAG DirectAccess Enabled Computers,OU=GPO Groups,OU=IT,DC=DCName,DC=com"
    $computerPath = "LDAP://CN=$ComputerName,OU=Location Workstations,OU=Corporate Office,DC=DCName,DC=com"
    $Group =[ADSI]"$GroupPath"

    If I run these commands line by line it works
    if I run the ps1 file nothing happens

    I've ran it with the same credentials as I do when running it line by line (so I know the rights are there)

    Any thoughts? I've been banging my head for 2 days....

  • #11135

    Points: 0
    Rank: Member

    Its not the cause of your problem but you could get the computer name in a simpler manner
    $computername = $env:COMPUTERNAME

    I'm not sure that you need the quotes on these 2 lines
    $Group =[ADSI]“$GroupPath”

    as you've already defined the strings

    Your code looks right – I'd suggest putting some debug code into the script to dump the contents of $grouppath and $computerpath so you can see that they are correctly formatted

  • #11161

    Points: 0
    Rank: Member

    So I figure it out I did change the script to make those couple of changes you suggested however it was a SCCM trick I needed to do...
    I had to run it like this:
    powershell -executionpolicy bypass -File AddSuperComputer2ADGroup.ps1

    I had a step to set the ExecutionPolicy to Unrestricted which didn't take thus the script blowing up

    Thank you!!!

    • #54778

      Points: 0
      Rank: Member

      Ron, do you have a copy of the final PowerShell script, I trying to do the same. but no good at PS. Could you send me a copy

The topic ‘SCCM 2012 / Add computer to AD Group during build’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort