afterCreate and Powershell rules

So in my AfterCreate PowerShell, I had the following function:

Function Write-CreateAppFile ($alias,$UPN,$sAMAccountName,$emailLicense)
{
  $fileName="CREATE-" + $sAMAccountName
  $Retry="0"
  $userFile=[pscustomobject]@{Alias=$alias; UPN=$UPN; sAMAccountName=$sAMAccountName; EmailLicense=$emailLicense; RetryCount=$Retry} 
  $userFile | Export-Csv -NoTypeInformation -Delimiter : -Path $AppFilePath\$fileName 
} 

Then I pulled data from the accountRequest object and inserted it into the file:

   $sAMAccountName=Get-AttributeValueFromAccountRequest $requestObject "SAMAccountName"
   $firstName=Get-AttributeValueFromAccountRequest $requestObject "extensionAttribute1"
   $lastName=Get-AttributeValueFromAccountRequest $requestObject "extensionAttribute3" 
   $upn=Get-AttributeValueFromAccountRequest $requestObject "userPrincipalName" 
   $alias=$upn.Split("@")[0]
   Write-CreateAppFile $alias $UPN $sAMAccountName $emailLicense

This would create a small file named CREATE-agutschow with a colon delimited data in a specific folder like:

Alias:UPN:sAMAccountName:EmailLicense:RetryCount
agutschow:[email protected]:agutschow:E3:0

Then my standalone program could get the list of files and process them like:

$fileList=@(Get-ChildItem -Path $newFilePath\* -File -Include CREATE*)

#For each file:
for ($i=0; $i  -le $fileList.Count -1; $i++)
{
    $fileName=$fileList[$i].Name
    $file = "$newFilePath\$fileName"
    $user = import-csv $file -Delimiter :
    $alias=$($user.alias)
    $UPN=$($user.UPN)
    $sAMAccountName=$($user.sAMAccountName)
    $emailLicense=$($user.EmailLicense)

   Continue Customer Logic

Hope this helps,

Alicia

1 Like