Script will not terminate properly - new user creation

Hi ppl,

I am developing a script to create a new user account in AD and have encountered an issue that i hope someone can help with.

The script is setup to be used with the Universal Dashboard (Community Edition) developed by Adam Driscoll.

I can use the current script to perform the following functions:

create a new user in an OU of my specification
copy groups from one user to the new user
create a homedrive folder
assign permissions to the homedrive folder based on the new account details
The issue i am having is when i try and set the Remote Services Profile path.

When i add the following code, the settings are applied to the new user account, however, the dashboard page will not print the completed status. Whereas, if i omit the RDS path portion, the script completes properly and i can see the account with all settings applied (minus the RDS as it has been omitted) and the Univ. D/Board displays the completed message.

In AD, even though the dashboard doesnt show the completed message, the user account has the profile path applied as expected.

$Dashboard = New-UDDashboard -Title “Test Dashboard” -Content {
New-UDInput -Title “Test Dashboard” -Endpoint {

new user creation portion omitted

$DisplayName = “Username”
$UserID = “userid”
$OUBase = “path to OU in AD”
$RemProfPath = “\server\folder$UserID”

below is the part of the script that does not allow the dashboard to complete

$UserInstancePID = Get-ADUser -SearchBase $OUBase -Filter {displayName -eq $DisplayName} -Properties company, department, distinguishedName, memberof, manager, mobilePhone, OfficePhone, SID, telephoneNumber ,title | Select-Object company, department, distinguishedName, memberof, manager, mobilePhone, OfficePhone, SID, telephoneNumber ,title
NewUser = [ADSI]"LDAP://($UserinstancePID.distinguishedName)"
$NewUser.psbase.invokeset(“terminalservicesprofilepath”,$RemProfPath)
$NewUser.setinfo()

above is the part of the script that does not allow the dashboard to complete

New-UDInputAction -Content {
New-UDCard -Title “Confirmation” -Text “The user account $DisplayName with User ID $UserID has been successfully created.”
}
} -Validate
}
Start-UDDashboard -Dashboard $Dashboard -Port 10001

Is there something that i am missing with regards to terminating/completing the part of the script that updates the RDS prof. path?

Your help is appreciated.

Regards,

It might be throwing an error even though its working. It also might be dropping something on the pipeline which (although I thought this was fixed) might be causing an issue with UDInput. Try modifying your script like this:

try {
$UserInstancePID = Get-ADUser -SearchBase $OUBase -Filter {displayName -eq $DisplayName} -Properties company, department, distinguishedName, memberof, manager, mobilePhone, OfficePhone, SID, telephoneNumber ,title | Select-Object company, department, distinguishedName, memberof, manager, mobilePhone, OfficePhone, SID, telephoneNumber ,title
$NewUser = [ADSI]"LDAP://($UserinstancePID.distinguishedName)"
$NewUser.psbase.invokeset(“terminalservicesprofilepath”,$RemProfPath) | Out-NUll
$NewUser.setinfo() | Out-Null
} catch {
 Show-UDToast -Message $_.Exception.Message
}

Thanks Adam.

I will give that a try over the weekend and report back.

Cheers,