Powershell script for new account creation - reset password, send email and add to group
€30-250 EUR
진행 중
게시됨 4년 이상 전
€30-250 EUR
제출할때 지불됩니다
Hello,
I'm looking to optimize and finish one of our scripts following need:
Either on the event AD account creation or once per day with a search filter all new accounts need to:
* Reset a password
* add to a group
* send an email to the new user.
Accounts are created by an external system, so account creation is NOT needed.
Just that the accounts are provisioned with a temp password which we don't know.
And we would like to send a welcome email with a PDF attached to the newly created accounts.
The trigger either being the Active directory account creation or in the morning with a scheduled task emailing all accounts created D-1
We have a basis, that you can use (or not):
##Beginning of functions
Function Send-Email {
Param ($Email, $Credential,$attachment)
$From = "Hello@[login to view URL]"
$subject = "Welcome to CompanyX"
$SMTPServer = "[login to view URL]"
$SMTPPort = "587"
### Beginning of email body
$Body = "Hello New user!,<br><br>"
$Body += "Welcome to CompanyX! <br><br>"
$Body += " This email will help you log in to Workday and Azure update your personal information before you start. <br><br>"
$Body += "Step 1. Enter your username (username)<br><br>"
$Body += "Step 2. Enter your password $UserPassword <br><br>"
$Body += " Please refer to the attached PDF for more information <br><br>"
$Body += "<br><br>"
$Body += "Looking forward to see you around,<br><br>"
$Body += "CompanyX Corporate "
### End of email body
Send-MailMessage -from $From -to $Email -Subject $subject -BodyAsHtml $Body -Attachments $attachment -SmtpServer $SMTPServer -Port $SMTPPort -Credential $Credential -UseSsl
}
### End of Functions
##### Beginning of main function
$When = ((Get-Date).AddDays(-1))
$UserName = "hello@[login to view URL]" #Gmail username which is used for sending an email
$Password = Get-Content "C:\CareBears\[login to view URL]" | ConvertTo-SecureString #Reading a secure password from file and reversing it back into a secure string object
$Credential = New-Object -TypeName [login to view URL] -ArgumentList ($UserName, $Password) #PSCredential for send-mail message cmdlet
$Attachment = "C:\CareBears\[login to view URL]" #PDF sending as an attachment with email
### Not finished ---- WIP
### $UserPassword = Get-Random -maximum 20000 -Minimum 100
### $UserPassword = "@" + "user" + $[login to view URL]()
### $UserPrincipalName = ($[login to view URL] + ”@[login to view URL]”)
foreach ($EmailAddress in Get-ADUser -filter {(whencreated -ge $When)} -Properties emailaddress | Select -ExpandProperty emailaddress) #Iterating over each email of users
{
Send-Email -Email $EmailAddress -Credential $Credential -attachment $Attachment
Write-Host "Email sent: $EmailAddress"
}
### End of main function
Hi,
I would like to work on this task and I will develop this in shell. I have five year of experience in this field. Please do let me know if we can discuss on this.
Regards,
Mayank