I have created this powershell code that creates new users and produces a report at the end of it.<\/p>\n
I need to know how to i can capture accounts that haven’t be created because it has the same Username connected.<\/p>\n
param(
\n[Parameter(Mandatory=$true)]$csvfile
\n)<\/p>\n
Import-Module activedirectory<\/p>\n
$users = Import-Csv -Path $csvfile<\/p>\n
foreach ($User in $Users) #creates<\/span> new users Write-Output “$(Get-Date) $SamAccountName Script excuted by $env:username” | Out-file C:\\temp\\test25.txt -append #Writes<\/span> a csv file with the username of created accounts and who creates it<\/p>\n }<\/p>","upvoteCount":5,"answerCount":12,"datePublished":"2019-04-11T09:35:04.000Z","author":{"@type":"Person","name":"jongomes1992","url":"https://community.spiceworks.com/u/jongomes1992"},"suggestedAnswer":[{"@type":"Answer","text":" I have created this powershell code that creates new users and produces a report at the end of it.<\/p>\n I need to know how to i can capture accounts that haven’t be created because it has the same Username connected.<\/p>\n param( Import-Module activedirectory<\/p>\n $users = Import-Csv -Path $csvfile<\/p>\n foreach ($User in $Users) #creates<\/span> new users Write-Output “$(Get-Date) $SamAccountName Script excuted by $env:username” | Out-file C:\\temp\\test25.txt -append #Writes<\/span> a csv file with the username of created accounts and who creates it<\/p>\n }<\/p>","upvoteCount":5,"datePublished":"2019-04-11T09:35:04.000Z","url":"https://community.spiceworks.com/t/needs-some-coding-advice/706899/1","author":{"@type":"Person","name":"jongomes1992","url":"https://community.spiceworks.com/u/jongomes1992"}},{"@type":"Answer","text":" Hello and welcome to the community!.<\/p>\n
\n{ $Displayname = $User.lastname + “,” + $User.Firstname
\n$GivenName = $User.Firstname
\n$Sn = $User.Lastname
\n$Name = “$($User.Lastname), $($User.Firstname)”
\n$SamAccountName = “$($User.Firstname).$($User.Lastname)”
\n$UserPrincipalName = $UserPrincipalName = $User.Firstname + “.” + $User.Lastname + “@test.ruh.local<\/span>” #Adds<\/span> User Principle Name which was missing from previous script
\n$ProfilePath = $User.OU #user<\/span> will be placed into the USERS ou on AD i will move them across manually
\n$Description = $User.Description
\n$password = $User.Password1<\/p>\n
\nNew-ADUser -DisplayName $Name -givenname “$GivenName” -Surname “$SN” -Name “$Name” -SamAccountName “$SamAccountName” -UserPrincipalName “$UserPrincipalName” -ProfilePath “$ProfilePath” -Description “$Description” -Enabled $False
\nAdd-ADGroupMember -identity Guests -Members $SamAccountName #adds<\/span> the groups
\nAdd-ADGroupMember -identity Users -Members $SamAccountName<\/p>\n
\n[Parameter(Mandatory=$true)]$csvfile
\n)<\/p>\n
\n{ $Displayname = $User.lastname + “,” + $User.Firstname
\n$GivenName = $User.Firstname
\n$Sn = $User.Lastname
\n$Name = “$($User.Lastname), $($User.Firstname)”
\n$SamAccountName = “$($User.Firstname).$($User.Lastname)”
\n$UserPrincipalName = $UserPrincipalName = $User.Firstname + “.” + $User.Lastname + “@test.ruh.local<\/span>” #Adds<\/span> User Principle Name which was missing from previous script
\n$ProfilePath = $User.OU #user<\/span> will be placed into the USERS ou on AD i will move them across manually
\n$Description = $User.Description
\n$password = $User.Password1<\/p>\n
\nNew-ADUser -DisplayName $Name -givenname “$GivenName” -Surname “$SN” -Name “$Name” -SamAccountName “$SamAccountName” -UserPrincipalName “$UserPrincipalName” -ProfilePath “$ProfilePath” -Description “$Description” -Enabled $False
\nAdd-ADGroupMember -identity Guests -Members $SamAccountName #adds<\/span> the groups
\nAdd-ADGroupMember -identity Users -Members $SamAccountName<\/p>\n