If you have your NetIQ IDM Engine on eDirectory which is running on a Windows Server, then you might just want to call PowerShell directly from the Engine; at least you have the capability of doing so.
The following code snippets (both DirXML Script and ECMAScript) will allow you to do just that. Of course, this only works on Windows, but it’s a good alternative if you would like any NetIQ IDM Driver to be able to execute PowerShell scripts.
DirXML Script
The following code will create a Home Folder when a User is created in Active Directory.<rule>
<description>[Windows] Create Home Folder Using Remote Powershell</description>
<conditions>
<and>
<if-global-variable mode="nocase" name="gcvHomeFolder-Script-OperatingSystem" op="equal">winblows</if-global-variable>
<if-operation op="equal">status</if-operation>
<if-xpath op="true">self::status[@level='success']</if-xpath>
<if-xpath op="true">./operation-data/class/text() = 'User'</if-xpath>
<if-op-property mode="nocase" name="final-operation" op="equal">add</if-op-property>
<if-xpath op="true">string-length(./operation-data/aib-info/home-folder/text()) > 0</if-xpath>
</and>
</conditions>
<actions>
<do-set-local-variable name="varUserName" scope="policy">
<arg-string>
<token-xpath expression="./operation-data/user-info/CN/text()"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="varHomeFolder" scope="policy">
<arg-string>
<token-xpath expression="./operation-data/aib-info/home-folder/text()"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="varRunAs_UN" scope="policy">
<arg-string>
<token-named-password name="np-HomeFolder-Username"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="varRunAs_PW" scope="policy">
<arg-string>
<token-named-password name="np-HomeFolder-Password"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="varCallType" scope="policy">
<arg-string>
<token-global-variable name="gcvHomeFolder-Script-PowershellActive"/>
</arg-string>
</do-set-local-variable>
<do-trace-message color="brgreen">
<arg-string>
<token-global-variable name="ConnectedSystemName"/>
<token-text xml:space="preserve"> : </token-text>
<token-text xml:space="preserve">About to create a Home Folder for User [</token-text>
<token-xpath expression="./operation-data/user-info/CN/text()"/>
<token-text xml:space="preserve">] on [</token-text>
<token-xpath expression="./operation-data/aib-info/home-folder/text()"/>
<token-text xml:space="preserve">] [</token-text>
<token-global-variable name="gcvHomeFolder-Script-PowershellExe"/>
<token-text xml:space="preserve">] [</token-text>
<token-global-variable name="gcvHomeFolder-Script-PowershellStub"/>
<token-text xml:space="preserve">] [</token-text>
<token-global-variable name="gcvHomeFolder-Script-PowershellActive"/>
<token-text xml:space="preserve">] {</token-text>
<token-local-variable name="varRunAs_UN"/>
<token-text xml:space="preserve"> </token-text>
<token-text xml:space="preserve">}</token-text>
</arg-string>
</do-trace-message>
<do-set-local-variable name="varPS_Result" scope="policy">
<arg-string>
<token-xpath expression="es:run_ps_scripts('~gcvHomeFolder-Script-PowershellExe~','~gcvHomeFolder-Script-PowershellStub~','~gcvHomeFolder-Script-PowershellActive~',$varUserName,$varHomeFolder,$varRunAs_UN,$varRunAs_PW)"/>
</arg-string>
</do-set-local-variable>
</actions>
</rule>
ECMAScript Function
importClass(java.lang.ProcessBuilder);
importClass(java.io.InputStreamReader);
importClass(java.io.BufferedReader);
importClass(java.lang.System);
importClass(java.util.ArrayList);
importClass(java.util.List);
function run_ps_scripts (power_shell, first_script, second_script, username, location, ra_un, ra_pw)
{
var varList = java.util.ArrayList();
varList.add(power_shell);
varList.add("-noprofile");
varList.add("-nologo");
varList.add("-noninteractive");
varList.add("-F");
varList.add(first_script);
varList.add(second_script);
varList.add(username);
varList.add(location);
varList.add(ra_un);
varList.add(ra_pw);
var varProBuilder = java.lang.ProcessBuilder (varList);
java.lang.System.out.println(varProBuilder.command());
var process = varProBuilder.start();
is = process.getInputStream();
isr = java.io.InputStreamReader(is);
br = java.io.BufferedReader(isr);
var line;
try
{
exitValue = process.waitFor();
java.lang.System.out.println("\nProgram exit was [" + exitValue + "]");
return exitValue;
}
catch (e)
{
e.printStackTrace();
return -1;
}
}