# Invoke PS Scripts

**URL:** <https://developer.sailpoint.com/discuss/t/invoke-ps-scripts/68243>\
**Category:** IIQ Discussion and Questions\
**Tags:** powershell-sdk, identityiq, provisioning\
**Created:** [June 24, 2024, 3:48pm UTC](https://developer.sailpoint.com/discuss/t/invoke-ps-scripts/68243 "2024-06-24T15:48:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![eneffati](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@eneffati](https://developer.sailpoint.com/discuss/u/eneffati)\
**Post date:** [June 24, 2024, 3:48pm UTC](https://developer.sailpoint.com/discuss/t/invoke-ps-scripts/68243/1 "2024-06-24T15:48:48Z")

</div>

### Which IIQ version are you inquiring about?

Version 8.3

### Share all details related to your problem, including any error messages you may have received.

Hello community,  
I’m creating a rule of type “ConnectorAfterCreate” to run a powershell script. I would like to know if there is a possibility to invoke other ps scripts from different folders.  
I called the script directly but it doesn’t seem to work ==\> $PSScriptRoot/myScript1.ps1

Thank you!

---

<div class="post-metadata">

**Author:** ![ashutosh08](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ashutosh08/32/11459_2.png) [@ashutosh08](https://developer.sailpoint.com/discuss/u/ashutosh08)\
**Post date:** [June 24, 2024, 4:43pm UTC](https://developer.sailpoint.com/discuss/t/invoke-ps-scripts/68243/2 "2024-06-24T16:43:16Z")

</div>

Hi @eneffati,

This is for IIQ or IdentityNow?

Thanks

---

<div class="post-metadata">

**Author:** ![KRM7](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/krm7/32/2685_2.png) [@KRM7](https://developer.sailpoint.com/discuss/u/KRM7)\
**Post date:** [June 24, 2024, 7:01pm UTC](https://developer.sailpoint.com/discuss/t/invoke-ps-scripts/68243/3 "2024-06-24T19:01:48Z")

</div>

Hi @eneffati

Welcome to SailPoint Developer Community.

Just invoke a PowerShell script from the ConnectorAfterCreate native Rule, don’t write much code in this Rule template, just use it as a template to call PS script.

You can call any number of scripts from this PS script file, just make sure that IQ Service account you are using in your AD source config has enough privileges to access the folders.

It is better if you can login to IQ Service server using the same service account.

Check this doc for more informatrion: [Before and After Operations on Source Account Rule | SailPoint Developer Community](https://developer.sailpoint.com/docs/extensibility/rules/connector-rules/before-and-after-rule-operations)

Thanks  
Krish

---

<div class="post-metadata">

**Author:** ![PhilRawlings1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/philrawlings1/32/37266_2.png) [@PhilRawlings1](https://developer.sailpoint.com/discuss/u/PhilRawlings1)\
**Post date:** [June 25, 2024, 8:37am UTC](https://developer.sailpoint.com/discuss/t/invoke-ps-scripts/68243/4 "2024-06-25T08:37:45Z")

</div>

Hi @eneffati and welcome,

As Krishna said, you _can_ call multiple scripts, I’m just questioning why you would want to.  
Personally, I have just the one script that does many things depending upon the input variables. It makes maintenance easier.

Phil

---

<div class="post-metadata">

**Author:** ![KRM7](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/krm7/32/2685_2.png) [@KRM7](https://developer.sailpoint.com/discuss/u/KRM7)\
**Post date:** [June 25, 2024, 8:58am UTC](https://developer.sailpoint.com/discuss/t/invoke-ps-scripts/68243/5 "2024-06-25T08:58:37Z")

</div>

It depends on requirements.

For example: In one implementation, I had to make below operations on AD account creation

1. Notify user AD password to the user’s manager
2. Enable Remote Mailbox  
…etc

I feel it is not good idea to keep all the logics in single script, so I prefer to have different PS scripts, If something goes wrong, it is easy to troubleshoot and no need to touch entire code.

It is better for understanding and maintenance.

Thanks  
Krishna

---

<div class="post-metadata">

**Author:** ![eneffati](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@eneffati](https://developer.sailpoint.com/discuss/u/eneffati)\
**Post date:** [June 25, 2024, 9:11am UTC](https://developer.sailpoint.com/discuss/t/invoke-ps-scripts/68243/6 "2024-06-25T09:11:48Z")

</div>

Yes indeed I wanted it to be more orgnaized and more important it’s a security matter.  
To invoke the ps scripts you used the normal PS command to call a script please?

---

<div class="post-metadata">

**Author:** ![KRM7](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/krm7/32/2685_2.png) [@KRM7](https://developer.sailpoint.com/discuss/u/KRM7)\
**Post date:** [June 25, 2024, 9:23am UTC](https://developer.sailpoint.com/discuss/t/invoke-ps-scripts/68243/7 "2024-06-25T09:23:30Z")

</div>

Yes, see the below code snippet.

```auto
try {
    #3 Exchange : Enable user mail box
    $exchange = "C:\SailPoint\Exchange_onprem.ps1"
    $command3 = -join ($exchange, " -samAccountName '$samAccountName' -mailPfx '$mailPfx' -mail '$mail'")
    $exchange_result = Invoke-Expression $command3
} catch {
    $ErrorMessage = $_.Exception.Message 
  	$ErrorItem = $_.Exception.ItemName
  	LogToFile("Mailbox Error: Item = $ErrorItem -> Message = $ErrorMessage")
}

```

> [@eneffati](#):
>
> if there is a possibility to invoke other ps scripts from different folders.

By the way, why not keep all the PS scripts in same folder, convenient rite.

Thanks  
Krish

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [August 24, 2024, 9:24am UTC](https://developer.sailpoint.com/discuss/t/invoke-ps-scripts/68243/8 "2024-08-24T09:24:04Z")

</div>

Closed on August 24, 2024, 9:24am UTC

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