AD.ps1
<#
.SYNOPSIS Import a CSV list of usernames to an Active Directory. .DESCRIPTION Import a CSV list of usernames to an Active Directory. Each user is provisionned with a temporary password and an enabled account. As of now, the Cmdlet must be executed locally on the desired server. .LINK Nexus Innovations : http://www.nexusinno.com -------------------------------------------------------------------------------------- Module 'Nexus.PSToolkit' by: Nexus Innovations. -------------------------------------------------------------------------------------- #> function global:Import-ADUsers() { Param( [Parameter(ParameterSetName='CSV')] [Parameter(Mandatory=$true)] [string]$CsvPath ) if(Test-Path $CsvPath) { Import-Csv $CsvPath | ForEach-Object { try { Write-Host "Provisioning user --> $($_.Name)..." -NoNewline New-ADUser -Name $_.Name -PasswordNeverExpires $True -PassThru | ` Set-ADAccountPassword -Reset -NewPassword (ConvertTo-SecureString $_.Password -AsPlainText -Force) -PassThru | ` Enable-ADAccount Write-Host "success!" -ForegroundColor Green } catch { Write-Host "failed!" -ForegroundColor Red } } } else { Write-Host "Supplied path is invalid!" -ForegroundColor Red } } <# .SYNOPSIS Remove a CSV list of usernames from an Active Directory. .DESCRIPTION Remove a CSV list of usernames from an Active Directory. Deletion is forced. As of now, the Cmdlet must be executed locally on the desired server. .LINK Nexus Innovations : http://www.nexusinno.com -------------------------------------------------------------------------------------- Module 'Nexus.PSToolkit' by: Nexus Innovations. -------------------------------------------------------------------------------------- #> function global:Clear-ADUsers { Param( [Parameter(ParameterSetName='CSV')] [string]$CsvPath ) if(Test-Path $CsvPath) { Import-Csv $CsvPath | ForEach-Object { try { Write-Host "Removing user $($_.Name)..." -NoNewline Remove-AdAccount -Identity $_.Name -Force Write-Host "success!" -ForegroundColor Green } catch { Write-Host "failed!" -ForegroundColor Red } } } } |