The original script doesn't use the AD cmdlets so it should work in WinPE. On Tue, Jun 21, 2016, 5:21 PM Murray, Mike <[email protected]> wrote:
> This doesn’t seem to be working via the TS. I’m guessing because the AD PS > module is not in our image. Anyone else have anything that might work for > this? > > > > *From:* [email protected] [mailto: > [email protected]] *On Behalf Of *Jerousek, Jeff > > *Sent:* Tuesday, June 21, 2016 11:52 AM > > > *To:* [email protected] > *Subject:* [mssms] RE: VB Script to add user to security group during > imaging? > > > > You are welcome. > > > > We don’t use MDT but these scripts work best with the ad user you are > running them as in the local admin group of that machine. > > > > We add the SCCM user at the start of the task sequence and remove it at > the end. > > > > *From:* [email protected] [ > mailto:[email protected] <[email protected]>] *On > Behalf Of *Murray, Mike > *Sent:* Tuesday, June 21, 2016 12:43 PM > *To:* [email protected] > *Subject:* [mssms] RE: VB Script to add user to security group during > imaging? > > > > I really appreciate your help! I was able to simplify this, I believe. I > haven’t tested in OSD just yet, but it works running locally. > > > > Param ( > > > > [Parameter(Mandatory = $true, HelpMessage = "AD Group > (distingiushedname)", Position = 0)] > > [string]$ADGroup, > > [Parameter(Mandatory = $true, HelpMessage = "User Sammacount”, > Position = 1)] > > [string]$userName > > > > ) > > > > Add-ADGroupMember -Identity $ADGroup -Members $userName > > > > > > > > > > > > *From:* [email protected] [ > mailto:[email protected] <[email protected]>] *On > Behalf Of *Jerousek, Jeff > *Sent:* Monday, June 20, 2016 11:27 AM > *To:* [email protected] > *Subject:* [mssms] RE: VB Script to add user to security group during > imaging? > > > > It should if you do something like this: > > > > Param ( > > > > [Parameter(Mandatory = $true, HelpMessage = "AD Group > (distingiushedname)", Position = 0)] > > [string]$ADGroup, > > [Parameter(Mandatory = $true, HelpMessage = "User Sammacount” Position = 1 > )] > > [string]$userName > > > > ) > > $search.Filter = "(sAMAccountName=$userName)" > > > > Then call it with something like powershell.exe .\scriptName.ps1 –Adgroup > %TSVar% -userName %TSVar2% > > > > Thanks, > > Jeff Jerousek <[email protected]> > > > > *From:* [email protected] [ > mailto:[email protected] <[email protected]>] *On > Behalf Of *Murray, Mike > *Sent:* Monday, June 20, 2016 11:44 AM > *To:* [email protected] > *Subject:* [mssms] RE: VB Script to add user to security group during > imaging? > > > > I need this to be able to read in the user name from a task sequence > variable. Will this do that? > > > > *From:* [email protected] [ > mailto:[email protected] <[email protected]>] *On > Behalf Of *Jerousek, Jeff > *Sent:* Monday, June 20, 2016 9:32 AM > *To:* [email protected] > *Subject:* [mssms] RE: VB Script to add user to security group during > imaging? > > > > Here is PS script that I use: > > > > Param ( > > > > [Parameter(Mandatory = $true, HelpMessage = "AD Group > (distingiushedname)", Position = 0)] > > [string]$ADGroup > > ) > > > > #Distinguished Name of group > > $name = $ADGroup > > > > #Get Domain > > $domain = [System.DirectoryServices.ActiveDirectory.Domain]:: > GetCurrentDomain() > > $root = $domain.GetDirectoryEntry() > > > > #Find user in Domain > > $search = [System.DirectoryServices.DirectorySearcher]$root > > $search.Filter = "(sAMAccountName=$env:USERNAME)" > > $result = $search.FindOne() > > $user = [ADSI]$result.path > > > > #Set Group Name > > $Ldap = "LDAP://" + $name > > [ADSI]$group = $LDAP > > > > #Add Computer to Named Group > > $group.psbase.Invoke("Add",$user.psbase.path) > > > > > > Thanks, > > Jeff Jerousek <[email protected]> > > > > *From:* [email protected] [ > mailto:[email protected] <[email protected]>] *On > Behalf Of *Murray, Mike > *Sent:* Monday, June 20, 2016 10:54 AM > *To:* [email protected] > *Subject:* [mssms] RE: VB Script to add user to security group during > imaging? > > > > :bump: > > > > *From:* [email protected] [ > mailto:[email protected] <[email protected]>] *On > Behalf Of *Murray, Mike > *Sent:* Thursday, June 16, 2016 4:26 PM > *To:* [email protected] > *Subject:* [mssms] VB Script to add user to security group during imaging? > > > > Hey folks, > > > > I have the script below that adds the **computer** account to a security > group via *“CSCRIPT.EXE AddGroup.vbs "Group Name"*. Could someone help me > modify it to add a user to the same group? The user would be a task > sequence variable (OSDUser or whatever). Thanks in advance! > > > > Const ADS_PROPERTY_APPEND = 3 > > Set WshShell = WScript.CreateObject("WScript.Shell") > > '----Get Computer DN------ > > > > Set objADSysInfo = CreateObject("ADSystemInfo") > > ComputerDN = objADSysInfo.ComputerName > > strcomputerdn = "LDAP://" & computerDN > > Set objADSysInfo = Nothing > > > > '----Connect AD----- > > > > Set oRoot = GetObject("LDAP://rootDSE") > > strDomainPath = oRoot.Get("defaultNamingContext") > > Set oConnection = CreateObject("ADODB.Connection") > > oConnection.Provider = "ADsDSOObject" > > oConnection.Open "Active Directory Provider" > > > > Count = WScript.Arguments.Count > > For i = 0 To count-1 > > Group = WScript.Arguments(i) > > Addgroup Group > > Next > > > > '----Get Group DN------ > > Function Addgroup(groupname) > > Set oRs = oConnection.Execute("SELECT adspath FROM > 'LDAP://" & strDomainPath & "'" & "WHERE objectCategory='group' AND " & > "Name='" & GroupName & "'") > > If Not oRs.EOF Then > > strAdsPath = oRs("adspath") > > End If > > If IsEmpty(strAdsPath) = False Then > > Const ADS_SECURE_AUTHENTICATION = 1 > > Set objGroup = GetObject(stradspath) > > Set objComputer = GetObject(strComputerDN) > > If (objGroup.IsMember(objComputer.AdsPath) > = False) Then > > objGroup.PutEx > ADS_PROPERTY_APPEND, "member", Array(computerdn) > > objGroup.SetInfo > > End If > > End If > > End Function > > > > > > Best Regards, > > > > Mike Murray > > Desktop Management Coordinator - IT Support Services > > California State University, Chico > > 530.898.4357 > [email protected] > > > > Remember, Chico State will NEVER ask you for your password via email! > > For more information about recognizing phishing scam emails go to: > http://www.csuchico.edu/isec/basics/spam-and-phishing.shtml > > > > > > > > > > > > > > > > > > >

