Invoking Powershell script from Rule

Hi All,

We have tried to invoke the PowerShell script through rule, it is creating the .ps1 file , but script is not getting executed.

If we try the same script from application connector Rule(native rule), it is working.

Any help will be appreciated!!.

Code snippet We are using to create the file :

FileCreationRule.xml

$value = New-Item -Path ‘\ServerPath\E$\test\testfile1112.emp’ -ItemType “File”;
$log.Debug(“exiting New-FileCreation”);
return $value;

code snippet to invoke the PowerShell script from rule:

String ruleName= "FileCreationRule";
Rule rules = context.getObject(Rule.class, ruleName);
Application ad = context.getObject(Application.class, "Active Directory");
List iqServiceConfig = ad.getAttributes().get("IQServiceConfiguration");
Map iqServiceConfigMap = iqServiceConfig.get(0);
String host = iqServiceConfigMap.get("IQServiceHost");
int port = Integer.parseInt(iqServiceConfigMap.get("IQServicePort"));
Map dataMap = new HashMap();
dataMap.put("postScript", rules);
dataMap.put("Application", ad.getAttributes());
RPCService service = new RPCService(host, port,false, false);
service.setConnectorServices(new sailpoint.connector.DefaultConnectorServices());
RpcRequest request = new RpcRequest("ScriptExecutor", "runAfterScript", dataMap);
RpcResponse response = service.execute(request);
if (response == null) {
return null;
}
if (response.getErrors() != null && response.getErrors().size() > 0) {
throw new IllegalStateException(response.getErrors().toString());
}

return response.toXml();

Thanks,
Prathyusha

In the example Compass post I shared in your original post - Creating file in Windows shared location from Sail Point IIQ - I didn’t see service.setConnectorServices(new sailpoint.connector.DefaultConnectorServices()); in the sample code.

As a basic troubleshooting step, I’d try creating a “dummy” powershell script that does something really simple, like writing some warning messages (via something like Write-Warning or Write-Error and create a local file/folder on the IQService host itself. That should help provide some indication of whether the issue is with the invocation of the script itself, or there’s something in the script that’s failing and not returning the failed status back to your rule’s invocation.

hi @Prathyusha_174

The code to invoke Powershell looks fine.
Could you try add following line in FileCreationRule.xml file at the beginig of the rule?

Add-type -path C:\<IQServicePath>\Utils.dll

As you mentioned, rule works properly though application connector Rule, because you are using IQService to provision, but when you try execute powershell code using external rule, in the code you are not importing IQService Library

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.