0 votes

I am trying to run this script on user delete.

$ProfilePath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\TS_Profiles\" + "%userPrincipalName%" + ".edu.v2"
Remove-Item $ProfilePath -recurse -force

i get this back from your software.

The string starting: At line:1 char:1 + <<<< ".edu.v2 is missing the terminator: ".

what is wrong?, it works in my script editor.

by (80 points)
0

Also note, this script works if I use the play button to test it. Even logged in as the user i have the service registered under. I don't understand. :?:

0

Hello,

We tested your script in our environment and it works perfectly.

Does the user logon name contain double quotes?
What will be displayed in the Execution Log if you add the following line in your script?

$Context.LogMessage("%userPrincipalName%", "Information")

What error is reported for the following line:

$ProfilePath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\TS_Profiles\%userPrincipalName%.edu.v2"

Try replacing double quotes with single quotes:

$ProfilePath = '\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\TS_Profiles\%userPrincipalName%.edu.v2'
0

For some reason, it started to work but i got this error on the last line of code.

Business Rules: 3 additional operations triggered

'Deleted Student Account': Run PowerShell script 'Delete TS Profile Directory' for the user
'Deleted Student Account': Run PowerShell script 'Delete User Home Directory' for the user
'Deleted Student Account': Run PowerShell script 'Delete User Redirected Folders' for the user
Error on last entry.
The specified network name is no longer available.

is this because the account was deleted and it can't find the username by the time it gets to the last line?

0

is this because the account was deleted and it can't find the username by the time it gets to the last line?

No, it is not possible. Can you post the text of the last script here?

0

I tried putting all the commands in one script and i get the same result. it randomly picks one of the deletes and fails on it.

$ProfilePath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\TS_Profiles\" + "%username%" + ".edu.v2"
Remove-Item $ProfilePath -recurse -force

$HomePath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\Home\" + "%username%"
Remove-Item $HomePath -recurse -force

$RedirPath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\Redirected\" + "%username%"
Remove-Item $RedirPath -recurse -force

1 Answer

0 votes
by (18.0k points)

Hello,

Your Business Rule cannot read the username property because the user object is deleted from AD (that's why a warning is shown when you save your Business Rule). The Business Rule works correctly only when the username property was cached prior to user deletion. So, to solve your problem you have two options:

1. Create another Business Rule that will be triggered BEFORE user deletion and execute the following PowerShell script:

$dummy = "%username%"

This script will cache the username property and it will be available for the Business Rule executed after user deletion.

  • OR -

2. [Recommended] Create a Business rule that will be executed before user deletion and save the user properties you need to a temporary file. The file name can contain the GUID of the user being deleted (the objectGUID property is always available after an object is deleted). The Business Rule that is executed after user deletion will read the username property from that file and do its job.

  • BEFORE user deletion:

      $fileName = $env:temp + "\%objectGuid%.adaxestmp";
      "%username%" | Out-File $fileName;
  • AFTER user deletion:

      $fileName = $env:temp + "\%objectGuid%.adaxestmp";
      $userName = Get-Content $fileName
      Remove-Item $fileName # delete the temporary file
    
      $ProfilePath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\TS_Profiles\" + $userName + ".edu.v2"
      Remove-Item $ProfilePath -recurse -force
      ...
0

Ok, i could do that, but i should just be able to change the rule to run before a user delete, so, i did that and i get the same error, now i am really confused.

0

Hello,

but i should just be able to change the rule to run before a user delete

You don't need to do this. The Business Rule that deprovisions users must be executed after user deletion, as the user deletion may fail or this operation can be sent for an approval.

i did that and i get the same error, now i am really confused.

This is very strange... Add the following line to your script:

$Context.LogMessage("The username is: " + $userName , "Information")

And see what is displayed in the Execution Log.

0

This is the result of adding the line you asked me to add. i added it to each little section of code.

'Before Account is Deleted': Run PowerShell script 'Cleanup User Profiles, Home Directory, etc.' for the user

The username is:
The username is:
The term 'Context.LogMessage' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. The specified network name is no longer available.

0

Just a note, this script fails even if i run it as a custom command and not tied to an event.

$ProfilePath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\TS_Profiles\" + "%username%" + ".edu.v2"
Remove-Item $ProfilePath -recurse -force

$HomePath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\Home\" + "%username%"
Remove-Item $HomePath -recurse -force

$RedirPath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\Redirected\" + "%username%"
Remove-Item $RedirPath -recurse -force

Same error as before. I can't wrap my head around this. can someone call me to trouble shoot this or is there someone i can call to walk thru this. thanks.

0

Hello,

The term 'Context.LogMessage' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. The specified network name is no longer available.

You need to put a dollar sign before 'Context.LogMessage' ($Context is a predefined variable):

$Context.LogMessage("The username is: " + $userName , "Information")

Please do the following:

  1. Create a new Custom Command for User objects.

  2. Add 'Run a PowerShell script' action to the command.

  3. Configure the action to execute the following PowerShell script:

     $Context.LogMessage("Username: " + "%username%", "Information")
    
     $ProfilePath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\TS_Profiles\" + "%username%" + ".edu.v2"
     $Context.LogMessage("ProfilePath: " + $ProfilePath, "Information")
    
     $HomePath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\Home\" + "%username%"
     $Context.LogMessage("HomePath: " + $HomePath, "Information")
    
     $RedirPath = "\\fs-edu1.edu.beacon-light.org\FS-EDU1_E\Redirected\" + "%username%"
     $Context.LogMessage("RedirPath: " + $RedirPath, "Information")
  4. Execute the Custom Command on a user account

  5. Post the Execution Log here.

If you want us to call you, please send me a PM with your phone number and time zone.

0

I made the changes you requested and there was no output. All i got was this.

Operation succeeded
Some additional operations triggered.

0

Can you post a screenshot here?

0

I'll give you a call in 20 minutes.

Related questions

0 votes
1 answer

Hi, I have this Script to check if a condition is met # The condition is met if $Context.ConditionIsMet is set to $True. $Context.ConditionIsMet = $False $inputString = " ... or issue with this match function using in a "if script returns true" condition?

asked Oct 31 by wintec01 (1.5k points)
0 votes
1 answer

Trying to create a custom command to run a powershell script, but I keep getting an error saying it can't find the file or path supplied for launching powershell. ... and I can launch powershell from this location using Command Prompt. Am I missing something?

asked Oct 24 by cstaub (100 points)
0 votes
1 answer

Having a strange issue, when executing a powershell command in adaxes as a business rule, the first line, no matter what is there comes up as invalid. Originally my ... line, but I've tried everything and universally the first line is flagged as invalid

asked Oct 23 by curtisa (290 points)
0 votes
1 answer

In a business rule, I'd like to pass Adaxes variables into a powershell script that I'll run. For example, pass %username% into the script so it can be used inside the script.

asked Sep 5 by P-Sysadmin (20 points)
0 votes
1 answer

Hi team, we have two accounts for Adaxes in our AD Service account (running services) named "service-adaxes" Service Domain account (to connect to AD) named "service-adaxesdomain" ... script? Or do I need to grant permissions to "service-adaxes" to manage AD?

asked Jul 30 by wintec01 (1.5k points)
3,548 questions
3,238 answers
8,232 comments
547,814 users