@@No1001-w8m okay, I’ll sort one out with a bit of scripting how to in there too for making lots of user accounts and adding people to groups and what not
Always great information, wish to see lots of PowerShell deep dive videos covering various troubleshooting aspects and scenarios in AWS and Azure using PowerShell and how to use PowerShell in those cloud environments conveniently.
@@cat19649 Here # Define the path to the CSV file $csvFilePath = "C:\Scripts\Users.csv" # Import the CSV if (Test-Path $csvFilePath) { $users = Import-Csv -Path $csvFilePath } else { Write-Error "CSV file not found at $csvFilePath" exit } # Loop through each user in the CSV foreach ($user in $users) { # Check if the user already exists $existingUser = Get-ADUser -Filter {SamAccountName -eq $user.SamAccountName} -ErrorAction SilentlyContinue if ($existingUser) { Write-Host "User $($user.SamAccountName) already exists. Skipping..." -ForegroundColor Yellow continue } # Create a new user try { New-ADUser ` -SamAccountName $user.SamAccountName ` -UserPrincipalName "$($user.SamAccountName)@yourdomain.com" ` -GivenName $user.GivenName ` -Surname $user.Surname ` -Name $user.DisplayName ` -DisplayName $user.DisplayName ` -AccountPassword (ConvertTo-SecureString $user.Password -AsPlainText -Force) ` -Enabled $true ` -Path $user.OU Write-Host "User $($user.SamAccountName) created successfully." -ForegroundColor Green } catch { Write-Error "Failed to create user $($user.SamAccountName). Error: $_" } } and here is example data for the csv SamAccountName,GivenName,Surname,DisplayName,Password,OU jdoe,John,Doe,John Doe,P@ssw0rd1,OU=Users,DC=example,DC=com asmith,Alice,Smith,Alice Smith,P@ssw0rd2,OU=IT,DC=example,DC=com bwhite,Bob,White,Bob White,P@ssw0rd3,OU=HR,DC=example,DC=com kpatel,Karen,Patel,Karen Patel,P@ssw0rd4,OU=Finance,DC=example,DC=com tgreen,Tom,Green,Tom Green,P@ssw0rd5,OU=Marketing,DC=example,DC=com
Yes, we want longer video on get-aduser and set-aduser :D
@@No1001-w8m okay, I’ll sort one out with a bit of scripting how to in there too for making lots of user accounts and adding people to groups and what not
Always great information, wish to see lots of PowerShell deep dive videos covering various troubleshooting aspects and scenarios in AWS and Azure using PowerShell and how to use PowerShell in those cloud environments conveniently.
@@supriyochatterjee4095 ok I will try and make in the future
@@mwcloud Thanks, much appreciated.
Nice video bro
Thanks
HI MIke thanks for nice videos if possible could u please do some realtime scnarios for devops enginner please interview prospect
What do you mean by realtime scenarios ?
@@mwcloud what kind of activities we do using powershell to automate some the tasks as devops engineer some scenarios
@@mwcloud request: create x# of new accounts. reality of admin: some accounts already exist, some need email updated, some need name updated.
@@cat19649 Here
# Define the path to the CSV file
$csvFilePath = "C:\Scripts\Users.csv"
# Import the CSV
if (Test-Path $csvFilePath) {
$users = Import-Csv -Path $csvFilePath
} else {
Write-Error "CSV file not found at $csvFilePath"
exit
}
# Loop through each user in the CSV
foreach ($user in $users) {
# Check if the user already exists
$existingUser = Get-ADUser -Filter {SamAccountName -eq $user.SamAccountName} -ErrorAction SilentlyContinue
if ($existingUser) {
Write-Host "User $($user.SamAccountName) already exists. Skipping..." -ForegroundColor Yellow
continue
}
# Create a new user
try {
New-ADUser `
-SamAccountName $user.SamAccountName `
-UserPrincipalName "$($user.SamAccountName)@yourdomain.com" `
-GivenName $user.GivenName `
-Surname $user.Surname `
-Name $user.DisplayName `
-DisplayName $user.DisplayName `
-AccountPassword (ConvertTo-SecureString $user.Password -AsPlainText -Force) `
-Enabled $true `
-Path $user.OU
Write-Host "User $($user.SamAccountName) created successfully." -ForegroundColor Green
} catch {
Write-Error "Failed to create user $($user.SamAccountName). Error: $_"
}
}
and here is example data for the csv
SamAccountName,GivenName,Surname,DisplayName,Password,OU
jdoe,John,Doe,John Doe,P@ssw0rd1,OU=Users,DC=example,DC=com
asmith,Alice,Smith,Alice Smith,P@ssw0rd2,OU=IT,DC=example,DC=com
bwhite,Bob,White,Bob White,P@ssw0rd3,OU=HR,DC=example,DC=com
kpatel,Karen,Patel,Karen Patel,P@ssw0rd4,OU=Finance,DC=example,DC=com
tgreen,Tom,Green,Tom Green,P@ssw0rd5,OU=Marketing,DC=example,DC=com