Hi Guys,
I’m trying to create Samaccountname based on the firstname and lastname in csv file.
$adusers.lastname.substring(0,4) with this command, I was able to get the first 4 letters from lastname and similarly was able to pull the first two letters from firstname.
This is our organization naming convention.
samaccount will start with U or V and followed by First 4 letters from last name and First 2 letters from first name. The csv will have a column that states employee type. If it is full-time employee, the sam ID should start with U. If any other category it should start with U.
e.g-> Wayne Rooney
UROONWA - Full Time
VROONWA - Part time or consultancy …etc
I’m very new to PowerShell any help will be greatly appreciated.
I ran the below cmd without $(), I got some error message. I used subexpression $() and after that, I got the below message
[string]::join('',$($adusers.lastname.substring(0,4)),$($adusers.firstname.substring(0,2)))
PS C:\Windows\system32> $($adusers.lastname.substring(0,4)) thir Rona mess PS C:\Windows\system32> [string]::Concat($adusers.lastname.substring(0,4),$adusers.firstname.substring(0,2)) System.Object[]System.Object[]
Commands which I was trying:
$adusers.firstname $adusers.lastname $ADUsers = Import-csv "E:\thiru\Automation\sampleinput.csv" $adusers.lastname.substring(0,4) $adusers.firstname.substring(0,2) [string]::join('',$($adusers.lastname.substring(0,4)),$($adusers.firstname.substring(0,2))) [string]::Concat($($adusers.lastname.substring(0,4)),$($adusers.firstname.substring(0,2)))
I tried both join and concatenate,
This is the message I get:
PS C:\Windows\system32> [string]::join('',$($adusers.lastname.substring(0,4)),$($adusers.firstname.substring(0,2))) System.Object[]System.Object[] PS C:\Windows\system32> [string]::Concat($($adusers.lastname.substring(0,4)),$($adusers.firstname.substring(0,2))) System.Object[]System.Object[] PS C:\Windows\system32>
Please help