Share via

Script create multi users with Windows PowerShell MAC address Change

dkarthi 21 Reputation points
2020-12-30T08:31:38.653+00:00

This is the link original script that you provide:

function Select-FileDialog

{

param([string]$Title,[string]$Directory,[string]$Filter="CSV Files (.csv)|.csv")

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null

$objForm = New-Object System.Windows.Forms.OpenFileDialog

$objForm.InitialDirectory = $Directory

$objForm.Filter = $Filter

$objForm.Title = $Title

$objForm.ShowHelp = $true

$Show = $objForm.ShowDialog()

If ($Show -eq "OK")

{

Return $objForm.FileName

}

Else

{

Exit

}

}

$FileName = Select-FileDialog -Title "Import an CSV file" -Directory "C:"

$ExchangeUsersOU = "OU=ExchangeUsers"

$domain = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()

$DomainDN = (([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Domains | ? {$_.Name -eq $domain}).GetDirectoryEntry().distinguishedName

$final = "LDAP://$DomainDN"

$DomainPath = [ADSI]"$final"

$cOU = $DomainPath.Create("OrganizationalUnit",$ExchangeUsersOU)

$cOU.SetInfo()

$UserInformation = Import-Csv $FileName

$OUPath = "LDAP://$ExchangeUsersOU,$DomainDN"

$UserPath = [ADSI]"$OUPath"

Write-Host "---------------------------------------------------------------"

Write-Host "Creating LAB Users"

Write-Host ""

Write-Host "---------------------------------------------------------------"

Foreach ($User in $UserInformation){

$CN = $User.samAccountName

$SN = $User.Surname

$Given = $User.givenName

$samAccountName = $User.samAccountName

$Display = $User.DisplayName

$LABUser = $UserPath.Create("User","CN=$CN")

Write-Host "Creating User: $User.samAccountName"

$LABUser.Put("samAccountName",$samAccountName)

$LABUser.Put("sn",$SN)

$LABUser.Put("givenName",$Given)

$LABUser.Put("displayName",$Display)

$LABUser.Put("mail","$samAccountName@$domain")

$LABUser.Put("description", "Lab User - created via Script")

$LABUser.Put("userPrincipalName","$samAccountName@$domain")

$LABUser.SetInfo()

$Pwrd = $User.Password

$LABUser.psbase.invoke("setPassword",$Pwrd)

$LABUser.psbase.invokeSet("AccountDisabled",$False)

$LABUser.psbase.CommitChanges()

}

Write-Host "Script Completed"

The PowerShell script was modified for my environment. in that scenario MAC address must be enabled in AD. while uploading the CSV file I have data, it was uploaded and users are created but I can't re-write or modify MAC address for bulk users' MAC address. Even can't change using PowerShell same CSV method. Kindly provide me a solution. Thanks in advance.

Windows for business | Windows Server | User experience | PowerShell

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.