Olá pessoal,
Hoje vamos ver como criar uma ferramenta web para criaçao de usuários no Active Directory usando powershell e o módulo UniversalDashboard. o Universal Dashboard é um modulo extremamente poderoso para a criação de Dashboards e Paginas Web usando apenas Powershell.
Criação de usuário:
param(
[Parameter(Mandatory)]
[string]$FirstName,
[Parameter(Mandatory)]
[string]$LastName,
[Parameter(Mandatory)]
[string]$UserName,
[Parameter(Mandatory)]
[ValidateSet("Tecnologia", "Recursos Humanos", "Contabilidade", "Marketing")]
[string]$Department
)
$password = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 20 |ForEach-Object -Process {[char]$_} )
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$NewAdUserParameters = @{
GivenName = $FirstName
Surname = $LastName
Name = $UserName
AccountPassword = $securePassword
Department = $Department
Enabled = $true
UserPrincipalName = '{0}@{1}' -f $UserName, $((Get-ADDomain).DNSRoot)
ChangePasswordAtLogon = $true
}
New-AdUser @NewAdUserParameters
Dashboard:
Import-Module UniversalDashboard.Community
$Dashboard = New-UDDashboard -Title "Create New AD User" -Content {
New-UDInput -Title "Create new user" -Content {
New-UDInputField -Name "FirstName" -Placeholder "First Name" -Type "textbox"
New-UDInputField -Name "LastName" -Placeholder "Last Name" -Type "textbox"
New-UDInputField -Name "UserName" -Placeholder "Account Name" -Type "textbox"
New-UDInputField -Name "Department" -Placeholder "Department" -Values "Tecnologia", "Recursos Humanos", "Contabilidade", "Marketing" -Type "select"
} -Endpoint {
param(
[Parameter(Mandatory)]
[string]$FirstName,
[Parameter(Mandatory)]
[string]$LastName,
[Parameter(Mandatory)]
[string]$UserName,
[Parameter(Mandatory)]
[ValidateSet("Tecnologia", "Recursos Humanos", "Contabilidade", "Marketing")]
[string]$Department
)
$password = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 20 |ForEach-Object -Process {[char]$_} )
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$NewAdUserParameters = @{
GivenName = $FirstName
Surname = $LastName
Name = $UserName
AccountPassword = $securePassword
Department = $Department
Enabled = $true
UserPrincipalName = '{0}@{1}' -f $UserName, $((Get-ADDomain).DNSRoot)
ChangePasswordAtLogon = $true
}
New-AdUser @NewAdUserParameters
New-UDInputAction -Content {
New-UDCard -Title "Temporary Password" -Text $Password
}
} -Validate
}
Start-UDDashboard -Dashboard $Dashboard -Port 80 -AutoReload
Dúvidas? Sugestões? Comente!
Até a Próxima