This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Workflow to execute script on remote server

Hi,

I am running Active Roles 6.9 and have created a workflow which should execute a PowerShell script on a remote server. If I run the script manually everything works fine. If I use the workflow I receive the message that the workflow executed successfully, but the script does not execute on the remote server. The script I am using is:

################################################################

function onPreMove($Request)
{
$User = $Dirobj.get("mail")

#Get's the credentials of the Active Roles Service Account
$Credential = Import-Clixml -Path "D:\TEMP\ARS.cred"

#Creates a connection to the on premise Skype for Business Management server
$Session =New-PSSession -computername Server01 -Authentication Credssp -Credential $Credential
$ScriptsBlock = {
Import-Module lync

#Reads the email address of the user and enables the user account for Skype for Business
$User = $using:User
$User2 = Get-CsAdUser -Filter {WindowsEmailAddress -like $User}
$SipAddres = "sip:" + $User2.WindowsEmailAddress
Enable-CsUser -Identity $User2.Identity -SipAddress $SipAddres -HostingProviderProxyFqdn "sipfed.online.lync.com"
}
Invoke-Command -Session $Session -ScriptBlock $ScriptsBlock
}

#######################################################################

Does anyone know if this is supported and or should work? 

Parents
  • Though not ideal, have you tested this using Basic authentication?

    I have tried to do something similar in the past and had to allow Basic authentication on the AR server.

    Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client -Name AllowBasic -Value 1

    ,,,and then set it back to zero when you are done.

Reply
  • Though not ideal, have you tested this using Basic authentication?

    I have tried to do something similar in the past and had to allow Basic authentication on the AR server.

    Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client -Name AllowBasic -Value 1

    ,,,and then set it back to zero when you are done.

Children
  • Hi,

    When I run the same script from the AR server it works fine. Could Basic Auth than still be an issue?

  • OK - I guess not.  FWIW, the last time I did something like this, I implemented it like this:

    Invoke-Command -computername $remotecomputer -credential $creds -ArgumentList $Var1,$Var2,$Var3 -ScriptBlock {<various PoSh commands }

    The ArgumentList corresponds to various parameters defined in the script block.

    Note that I didn't launch a remote PS-Session.

    I'm not saying that what you are doing is wrong but this is what worked for me.  FYI, my script used a PS module that was locally installed on the remote server so in that way, similar to what you are doing.

  • Hi,

    After enabling debugging on the script through AR I see the following error message:

    ERROR:
    At line: 3 char:1. Exception calling "Get" with "1" argument(s): "The directory property cannot be found in the cache.


    The specified property 'mail' cannot be found in the property cache."

    Any suggestions?