Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Extensions/Add-XADGroupMember.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function Add-XADGroupMember {
param ([Parameter(Mandatory = $true)][string]$Domain)

$Username = read-host -Prompt "Username"
$Group = read-host -Prompt "Group"
$Username = Read-Host -Prompt "Username"
$Group = Read-Host -Prompt "Group"
Write-Host "`nAdding '$Username' to $Group in $Domain..............`n" -ForegroundColor Yellow
try {
Add-ADGroupMember $Group -Members $Username -ErrorAction Stop
Expand All @@ -13,3 +13,9 @@ function Add-XADGroupMember {
Write-Host "Adding '$Username' to $Group in $Domain domain failed. ErrorDetails: $ErrorDetails" -ForegroundColor Red
}
}






80 changes: 46 additions & 34 deletions Extensions/New-XADAdmin.ps1
Original file line number Diff line number Diff line change
@@ -1,42 +1,54 @@

function New-XADAdmin {
[CmdletBinding(SupportsShouldProcess = $true)]
param ([Parameter(Mandatory = $true)][string]$Domain)
begin {}
process {
if ($pscmdlet.ShouldProcess("domain - $Domain")) {
$DomainDNRoot = (Get-ADDomain).DistinguishedName
$DomainDNSSuffix = (Get-ADDomain).DNSRoot

$DomainDNRoot = (Get-ADDomain).DistinguishedName
$DomainDNSSuffix = (Get-ADDomain).DNSRoot
$Username = Read-Host -Prompt "Username"
$Password = Read-Host -Prompt "Password" -AsSecureString
$Description = Read-Host -Prompt "Description"
$Mobile = Read-Host -Prompt "Mobile"

$Username = read-host -Prompt "Username"
$Password = read-host -Prompt "Password" -AsSecureString
$Description = read-host -Prompt "Description"
$Mobile = read-host -Prompt "Mobile"
$Path = Read-Host -Prompt "Enter the OU name for admin users (default: Admin Accounts)"
if ([string]::IsNullOrWhiteSpace($Path)) {
$Path = "Admin Accounts"
}
$Path = $Path.Trim()
$Path = "OU=" + $Path + "," + $DomainDNRoot

$Path = Read-Host -Prompt "Enter the OU name for admin users (default: Admin Accounts)"
if ([string]::IsNullOrWhiteSpace($Path)) {
$Path = "Admin Accounts"
}
$Path = $Path.Trim()
$Path = "OU=" + $Path + "," + $DomainDNRoot

Write-Host "`nCreating new admin user '$Username' in $Domain under $Path..............`n" -ForegroundColor Yellow
$UserParams = @{
Name = $UserName
GivenName = $UserName
Surname = ""
UserPrincipalName = "$UserName@$DomainDNSSuffix"
SamAccountName = $UserName
Description = $Description
DisplayName = $UserName
Path = $Path
AccountPassword = $Password
Enabled = $true
Mobile = $Mobile
}
try {
New-ADUser @UserParams -ErrorAction Stop
Write-Host "Account creation succeeded for '$Username' in $Domain domain." -ForegroundColor Green
}
catch {
$ErrorDetails = $_.Exception.Message
Write-Host "Account creation failed for '$Username' in $Domain domain. ErrorDetails: $ErrorDetails" -ForegroundColor Red
Write-Host "`nCreating new admin user '$Username' in $Domain under $Path..............`n" -ForegroundColor Yellow
$UserParams = @{
Name = $UserName
GivenName = $UserName
Surname = ""
UserPrincipalName = "$UserName@$DomainDNSSuffix"
SamAccountName = $UserName
Description = $Description
DisplayName = $UserName
Path = $Path
AccountPassword = $Password
Enabled = $true
Mobile = $Mobile
}
try {
New-ADUser @UserParams -ErrorAction Stop
Write-Host "Account creation succeeded for '$Username' in $Domain domain." -ForegroundColor Green
}
catch {
$ErrorDetails = $_.Exception.Message
Write-Host "Account creation failed for '$Username' in $Domain domain. ErrorDetails: $ErrorDetails" -ForegroundColor Red
}
}
}
end {}
}






110 changes: 61 additions & 49 deletions Extensions/New-XADServiceAccount.ps1
Original file line number Diff line number Diff line change
@@ -1,55 +1,67 @@
function New-XADServiceAccount {
[CmdletBinding(SupportsShouldProcess = $true)]
param ([Parameter(Mandatory = $true)][string]$Domain)
begin {}
process {
if ($pscmdlet.ShouldProcess("domain - $Domain")) {
$DomainDNRoot = (Get-ADDomain).DistinguishedName
$DomainDNSSuffix = (Get-ADDomain).DNSRoot

$DomainDNRoot = (Get-ADDomain).DistinguishedName
$DomainDNSSuffix = (Get-ADDomain).DNSRoot

$OUPath = Read-Host -Prompt "Enter the name of the existing main OU (default: Service Accounts)"
if ([string]::IsNullOrWhiteSpace($OUPath)) {
$OUPath = "Service Accounts"
}
$OUPath = $OUPath.Trim()
$OUPath = "OU=" + $OUPath + "," + $DomainDNRoot
do {
$OUName = Read-Host -Prompt "Enter the name of the new sub OU"
} while ([string]::IsNullOrWhiteSpace($OUName))
$OUName = $OUName.Trim()
Write-Host "`nCreating $OUName OU under $OUPath in $Domain domain..............`n" -ForegroundColor Yellow
try {
New-ADOrganizationalUnit -Name $OUName -Path $OUPath -ErrorAction Stop
Write-Host "OU creation succeeded for OU $OUName in $Domain domain." -ForegroundColor Green
}
catch {
$ErrorDetails = $_.Exception.Message
Write-Host "OU creation failed for $OUName in $Domain domain. ErrorDetails: $ErrorDetails" -ForegroundColor Red
}
do {
$Username = read-host -Prompt "Service Account Username"
} while ([string]::IsNullOrWhiteSpace($Username))
$OUPath = Read-Host -Prompt "Enter the name of the existing main OU (default: Service Accounts)"
if ([string]::IsNullOrWhiteSpace($OUPath)) {
$OUPath = "Service Accounts"
}
$OUPath = $OUPath.Trim()
$OUPath = "OU=" + $OUPath + "," + $DomainDNRoot
do {
$OUName = Read-Host -Prompt "Enter the name of the new sub OU"
} while ([string]::IsNullOrWhiteSpace($OUName))
$OUName = $OUName.Trim()
Write-Host "`nCreating $OUName OU under $OUPath in $Domain domain..............`n" -ForegroundColor Yellow
try {
New-ADOrganizationalUnit -Name $OUName -Path $OUPath -ErrorAction Stop
Write-Host "OU creation succeeded for OU $OUName in $Domain domain." -ForegroundColor Green
}
catch {
$ErrorDetails = $_.Exception.Message
Write-Host "OU creation failed for $OUName in $Domain domain. ErrorDetails: $ErrorDetails" -ForegroundColor Red
}
do {
$Username = Read-Host -Prompt "Service Account Username"
} while ([string]::IsNullOrWhiteSpace($Username))

$Password = read-host -Prompt "Service Account Password" -AsSecureString
$Description = read-host -Prompt "Service Account Description"
$Path = "OU=" + $OUName + "," + $OUPath;
$NewUserParams = @{
Name = $Username
GivenName = $Username
Surname = ""
UserPrincipalName = "$Username@$DomainDNSSuffix"
SamAccountName = $Username
Description = $Description
DisplayName = $Username
Path = $Path
AccountPassword = $Password
Enabled = $true
PasswordNeverExpires = $true
}
Write-Host "`nCreating service account '$Username' in $Domain domain under $Path..............`n" -ForegroundColor Yellow
try {
New-ADUser @NewUserParams -ErrorAction Stop
Write-Host "Account creation succeeded for '$Username' in $Domain domain." -ForegroundColor Green
}
catch {
$ErrorDetails = $_.Exception.Message
Write-Host "Service Account creation failed for '$Username' in $Domain domain. ErrorDetails: $ErrorDetails" -ForegroundColor Red
$Password = Read-Host -Prompt "Service Account Password" -AsSecureString
$Description = Read-Host -Prompt "Service Account Description"
$Path = "OU=" + $OUName + "," + $OUPath;
$NewUserParams = @{
Name = $Username
GivenName = $Username
Surname = ""
UserPrincipalName = "$Username@$DomainDNSSuffix"
SamAccountName = $Username
Description = $Description
DisplayName = $Username
Path = $Path
AccountPassword = $Password
Enabled = $true
PasswordNeverExpires = $true
}
Write-Host "`nCreating service account '$Username' in $Domain domain under $Path..............`n" -ForegroundColor Yellow
try {
New-ADUser @NewUserParams -ErrorAction Stop
Write-Host "Account creation succeeded for '$Username' in $Domain domain." -ForegroundColor Green
}
catch {
$ErrorDetails = $_.Exception.Message
Write-Host "Service Account creation failed for '$Username' in $Domain domain. ErrorDetails: $ErrorDetails" -ForegroundColor Red
}
}
}
end {}
}






66 changes: 39 additions & 27 deletions Extensions/Reset-XADUserPassword.ps1
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@

function Reset-XADUserPassword {
[CmdletBinding(SupportsShouldProcess = $true)]
param ([Parameter(Mandatory = $true)][string]$Domain)
begin {}
process {
if ($pscmdlet.ShouldProcess("domain - $Domain")) {
$Username = Read-Host -Prompt "Username"
Write-Host "`nFetching account details for '$Username' in $Domain domain..............`n" -ForegroundColor Yellow

$Username = read-host -Prompt "Username"
Write-Host "`nFetching account details for '$Username' in $Domain domain..............`n" -ForegroundColor Yellow

try {
$Useraccount = Get-ADUser $Username -Properties mobile, PasswordLastSet, PasswordNeverExpires, PasswordExpired, msDS-UserPasswordExpiryTimeComputed -ErrorAction Stop
Write-Host "Account details for $Username from $Domain domain:" -ForegroundColor Green
$Useraccount | Select-Object mobile, PasswordLastSet, PasswordNeverExpires, PasswordExpired, @{Name = "PasswordExpiryDate"; Expression = { [datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed") } }
}
catch {
$ErrorDetails = $_.Exception.Message
Write-Host "Failed to fetch details for '$Username' in $Domain domain. ErrorDetails: $ErrorDetails" -ForegroundColor Red
return
}
$Password = read-host -Prompt "Password" -AsSecureString
$Confirm = Read-Host -Prompt "Are you sure you want to reset the password for $Username in $Domain domain?`n Type 'y' or 'Y' to continue"
if ($Confirm -notin 'y', 'Y') {
return
try {
$Useraccount = Get-ADUser $Username -Properties mobile, PasswordLastSet, PasswordNeverExpires, PasswordExpired, msDS-UserPasswordExpiryTimeComputed -ErrorAction Stop
Write-Host "Account details for $Username from $Domain domain:" -ForegroundColor Green
$Useraccount | Select-Object mobile, PasswordLastSet, PasswordNeverExpires, PasswordExpired, @{Name = "PasswordExpiryDate"; Expression = { [datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed") } }
}
catch {
$ErrorDetails = $_.Exception.Message
Write-Host "Failed to fetch details for '$Username' in $Domain domain. ErrorDetails: $ErrorDetails" -ForegroundColor Red
return
}
$Password = Read-Host -Prompt "Password" -AsSecureString
$Confirm = Read-Host -Prompt "Are you sure you want to reset the password for $Username in $Domain domain?`n Type 'y' or 'Y' to continue"
if ($Confirm -notin 'y', 'Y') {
return
}
Write-Host "`nSetting password for '$Username' in $Domain domain..............`n" -ForegroundColor Yellow
try {
$Useraccount | Set-ADAccountPassword -NewPassword $Password -Reset -ErrorAction Stop
Write-Host "Password reset succeeded for '$Username' in $Domain domain." -ForegroundColor Green
}
catch {
$ErrorDetails = $_.Exception.Message
Write-Host "Password reset failed for '$Username' in $Domain domain. ErrorDetails: $ErrorDetails" -ForegroundColor Red
}
}
}
Write-Host "`nSetting password for '$Username' in $Domain domain..............`n" -ForegroundColor Yellow
try {
$Useraccount | Set-ADAccountPassword -NewPassword $Password -Reset -ErrorAction Stop
Write-Host "Password reset succeeded for '$Username' in $Domain domain." -ForegroundColor Green
}
catch {
$ErrorDetails = $_.Exception.Message
Write-Host "Password reset failed for '$Username' in $Domain domain. ErrorDetails: $ErrorDetails" -ForegroundColor Red
}
}
end {}
}






7 changes: 6 additions & 1 deletion Functions/Get-XADConfig.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
function Get-XADConfig {
Import-Csv $script:DCIPsCSVPath
}
}





10 changes: 8 additions & 2 deletions Functions/New-XADDrive.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function New-XADDrive {
)]
[switch]$NoConnectionTest = $false
)
PROCESS {
process {
foreach ($DomainController in $DomainControllers) {
if ($NoConnectionTest) {
$Server = $DomainController
Expand All @@ -56,7 +56,7 @@ function New-XADDrive {
break
}
}
if (-Not $Server) {
if (-not $Server) {
$ErrorRecord = [System.Management.Automation.ErrorRecord]::new(
[System.Management.Automation.DriveNotFoundException]::new("Unable to create an Active Directory drive because none of the supplied domain controllers was reachable."),
'ADDriveCreationFailed',
Expand All @@ -79,3 +79,9 @@ function New-XADDrive {
$ADDrive
}
}






Loading