Hi All:
I’m 95% done on a project but am struggling with the final piece. I only took one coding class as an undergrad and I don’t have a lot of experience in it. Scenario: users fill out a webform on our intranet when a new hire arrives. This data goes into an SQL server. I have the code written which:
- asks me via console input for the user last name. I type in the last name and hit enter.
- it then queries the sql database and returns the user in question (query only goes back 30 days to prevent retrieving an old record of someone w the same last name).
- AD user is created in an OU I specify from a tree.
- Exchange account is created.
samaccount
parameter onto the Add-ADGroupMember
command.
Invoke-Sqlcmd -ServerInstance mysqlservername -Database mydatabasename -Query “SELECT * FROM dbo.NewUserForm WHERE Emp_LastName= ‘$MYVAR1’ AND DateReceived >= DATEADD(day, -30, GETDATE())” |
select @{l=‘Name’;e={$.Emp_FirstName+" "+$.Emp_LastName}},
@{l=‘SamAccountName’;e={$.Emp_FirstName.tolower().substring(0,1)+$.Emp_LastName.tolower()}},
@{l=‘UserPrincipalName’;e={$.Emp_FirstName.tolower().substring(0,1)+$.Emp_LastName.tolower()+“@contoso.local”}},
@{l=‘DisplayName’;e={$.Emp_FirstName+" "+$.Emp_LastName}},
@{l=‘GivenName’;e={$.Emp_FirstName}},
@{l=‘Surname’;e={$
.Emp_LastName}},
@{l=‘Title’ ;e={$.JobTitle}},
@{l=‘OfficePhone’;e={$
.PhoneNumber}} |
New-ADUser -Path “$($xyy)” -Country “us” -ChangePasswordAtLogon $True -State “WA” -City “Contosoville” -StreetAddress “$($theaddress)” -PassThru |
select Name, SamAccountName, UserPrincipalName
Add-ADGroupMember -members SamAccountName -Identity $thegroups
I know I am close. At least I think I am. Any help would be appreciated!