Last active
June 7, 2023 21:50
-
-
Save wallentx/48559abbbe1c59ea6c0b11ef6fefc1c6 to your computer and use it in GitHub Desktop.
YoU wOuLdNt PuT pOwErShElL iN yAmL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"schemaVersion": "2.2", | |
"description": "Create AD User (writing this gave me AIDS)", | |
"parameters": { | |
"userName": { | |
"type": "String", | |
"default": "Enabled" | |
}, | |
"firstName": { | |
"type": "String", | |
"default": "Enabled" | |
}, | |
"lastName": { | |
"type": "String", | |
"default": "Enabled" | |
} | |
}, | |
"mainSteps": [ | |
{ | |
"action": "aws:runPowerShellScript", | |
"name": "createAdUser", | |
"timeoutSeconds": 30, | |
"inputs": { | |
"runCommand": [ | |
"$VerbosePreference = \"Continue\"", | |
"$ErrorActionPreference = \"Stop\"", | |
"$ADUser = (Get-SSMParameterValue -Name thisIsAss).Parameters[0].Value", | |
"$ADPass = (Get-SSMParameterValue -Name whyAmIDoingThis -WithDecryption $True).Parameters[0].Value | ConvertTo-SecureString -asPlainText -Force", | |
"$ADCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ADUser,$ADPass", | |
"$Name = '{{ userName }}'", | |
"$User = Get-ADUser -Filter {sAMAccountName -eq $Name}", | |
"If ($User -ne $Null) { echo 'User already exists.' exit 1 }", | |
"New-ADUser -Credential $ADCreds -GivenName '{{ firstName }}' -Surname '{{ lastName }}' -Name '{{ userName }}' -DisplayName '{{ userName }}' -SamAccountName '{{ userName }}' -UserPrincipalName '{{ userName }}''@please.kill.me' -Path 'OU=Users,OU=active,DC=directory,DC=can,DC=die' -PasswordNotRequired $true -ChangePasswordAtLogon $true -Enabled $true -Passthru | ForEach-Object { Add-ADGroupMember -Credential $ADCreds -Identity 'CN=Garbage,OU=Powershell,OU=makes,DC=my,DC=nuts,DC=hurt' -Members $_ } " | |
] | |
} | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
schemaVersion: "2.2" | |
description: "Create AD User (writing this gave me AIDS)" | |
parameters: | |
userName: | |
type: String | |
default: Enabled | |
firstName: | |
type: String | |
default: Enabled | |
lastName: | |
type: String | |
default: Enabled | |
mainSteps: | |
- action: aws:runPowerShellScript | |
name: createAdUser | |
timeoutSeconds: 30 | |
inputs: | |
runCommand: | |
- '$VerbosePreference = "Continue"' | |
- '$ErrorActionPreference = "Stop"' | |
- $ADUser = (Get-SSMParameterValue -Name thisIsAss).Parameters[0].Value | |
- $ADPass = (Get-SSMParameterValue -Name whyAmIDoingThis -WithDecryption $True).Parameters[0].Value | ConvertTo-SecureString -asPlainText -Force | |
- $ADCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ADUser,$ADPass | |
- "$Name = '{{ userName }}'" | |
- $User = Get-ADUser -Filter {sAMAccountName -eq $Name} | |
- "If ($User -ne $Null) { | |
echo 'User already exists.' | |
exit 1 | |
}" | |
- "New-ADUser | |
-Credential $ADCreds | |
-GivenName '{{ firstName }}' | |
-Surname '{{ lastName }}' | |
-Name '{{ userName }}' | |
-DisplayName '{{ userName }}' | |
-SamAccountName '{{ userName }}' | |
-UserPrincipalName '{{ userName }}''@please.kill.me' | |
-Path 'OU=Users,OU=active,DC=directory,DC=can,DC=die' | |
-PasswordNotRequired $true | |
-ChangePasswordAtLogon $true | |
-Enabled $true | |
-Passthru | ForEach-Object { | |
Add-ADGroupMember | |
-Credential $ADCreds | |
-Identity 'CN=Garbage,OU=Powershell,OU=makes,DC=my,DC=nuts,DC=hurt' | |
-Members $_ | |
} | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment