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]]
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 <mailto:[email protected]> 

 

From: [email protected] <mailto:[email protected]>
[mailto:[email protected]] On Behalf Of Murray, Mike
Sent: Monday, June 20, 2016 10:54 AM
To: [email protected] <mailto:[email protected]> 
Subject: [mssms] RE: VB Script to add user to security group during imaging?

 

:bump:

 

From: [email protected] <mailto:[email protected]>
[mailto:[email protected]] On Behalf Of Murray, Mike
Sent: Thursday, June 16, 2016 4:26 PM
To: [email protected] <mailto:[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
 <mailto:[email protected]> [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

 

 

 

 

 



Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to