Question : Syntax question for creating a ps1 powershell script to create contacts in Exchange 2007

I have this example of a script I got on a blog.

# Create User Accounts & Mailboxes According to Information in contacts.csv (CSV Formatted)
# NOTE: Be sure that the Contacts.csv file resides in the same directory as the script when running.
# $_. (defined by $entry) calls the column in the CSV (e.g. $_.First calls the data from csv column titled First)
# $_.First is First Name
# $_.Last is Last Name
# $DN is Display Name
# $uLogin is User Login Name
# $OU is the Organizational Unit for User Objects (String Value enclosed in '')
# $Domain is the UPN Domain Name (either internal Domain Name or Public Domain Name if added as additional UPN Domain in Domains & Trusts, string value enclosed in '')
# $Server is the Database Serer Name (String value enclosed in '')
# $SG is the Storage Group Name for hosting Mailboxes
# $MDB is the Mailbox Database Name for hosting Mailboxes
# Define Common Variables
$OU = 'Contacts'
# Call CSV File & Create Mailboxes
Write-host "Creating Contacts..."
import-csv 'contacts.csv' |
 foreach{
  $entry = $_
  $DN = $_.First+" " +$_.Last;
  $Alias = $_.First+"_" +$_.Last
  New-MailContact $DN -DisplayName $DN -FirstName $_.First -LastName $_.Last -organizationalunit $OU -Alias $Alias -ExternalEmailAddress $_.email
  Set-Contact $DN -Company $_.Company -Title $_.Title -Department $_.Department -Fax $_.Fax -MobilePhone $_.Mobile -Office $_.Location -Phone $_.Tel -PostalCode $_.Zip -PostOfficeBox $_.POBox -City $_.City -StreetAddress $_.StreetAdd -CountryorRegion $_.Country
  Write-Host 'OU   =' $OU
  Write-host 'First Name  =' $_.First
  Write-Host 'Last Name  =' $_.Last
  write-host 'Display Name  =' $DN
  Write-Host 'Alias   =' $Alias
  Write-Host 'Email Address  =' $_.Email
  Write-Host 'Company  =' $_.Company
  Write-Host 'Office  =' $_.Location
  Write-Host 'Title  =' $_.Title
  Write-Host 'Department =' $_.Department
  Write-Host 'Telephone =' $_.Tel
  Write-Host 'Fax  =' $_.Fax
  Write-Host 'Mobile No.  =' $_.Mobile
 
  }

My question has to do with this line :
  $Alias = $_.First+"_" +$_.Last
I do not want the alias in this format, I want it to be first initial and last 5 of last name. What would I replace this with? I cannot find anything on the Inet to help me with this syntax request.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
# Create User Accounts & Mailboxes According to Information in contacts.csv (CSV Formatted)
# NOTE: Be sure that the Contacts.csv file resides in the same directory as the script when running.
# $_. (defined by $entry) calls the column in the CSV (e.g. $_.First calls the data from csv column titled First)
# $_.First is First Name
# $_.Last is Last Name
# $DN is Display Name
# $uLogin is User Login Name
# $OU is the Organizational Unit for User Objects (String Value enclosed in '')
# $Domain is the UPN Domain Name (either internal Domain Name or Public Domain Name if added as additional UPN Domain in Domains & Trusts, string value enclosed in '')
# $Server is the Database Serer Name (String value enclosed in '')
# $SG is the Storage Group Name for hosting Mailboxes
# $MDB is the Mailbox Database Name for hosting Mailboxes
# Define Common Variables
$OU = 'Contacts'
# Call CSV File & Create Mailboxes
Write-host "Creating Contacts..."
import-csv 'contacts.csv' |
 foreach{
  $entry = $_
  $DN = $_.First+" " +$_.Last;
  $Alias = $_.First+"_" +$_.Last
  New-MailContact $DN -DisplayName $DN -FirstName $_.First -LastName $_.Last -organizationalunit $OU -Alias $Alias -ExternalEmailAddress $_.email
  Set-Contact $DN -Company $_.Company -Title $_.Title -Department $_.Department -Fax $_.Fax -MobilePhone $_.Mobile -Office $_.Location -Phone $_.Tel -PostalCode $_.Zip -PostOfficeBox $_.POBox -City $_.City -StreetAddress $_.StreetAdd -CountryorRegion $_.Country
  Write-Host 'OU   =' $OU
  Write-host 'First Name  =' $_.First
  Write-Host 'Last Name  =' $_.Last
  write-host 'Display Name  =' $DN
  Write-Host 'Alias   =' $Alias
  Write-Host 'Email Address  =' $_.Email
  Write-Host 'Company  =' $_.Company
  Write-Host 'Office  =' $_.Location
  Write-Host 'Title  =' $_.Title
  Write-Host 'Department =' $_.Department
  Write-Host 'Telephone =' $_.Tel
  Write-Host 'Fax  =' $_.Fax
  Write-Host 'Mobile No.  =' $_.Mobile
  
  }
Open in New Window Select All

Answer : Syntax question for creating a ps1 powershell script to create contacts in Exchange 2007

I think this is it, it seemed to work.

$Alias = $_.First .Substring(0,1)+$_.Last.Substring(0,6)
Random Solutions  
 
programming4us programming4us