none
workflow powershell activity - postprocessing RRS feed

  • Question

  • I have sleep command in the script, that could make the script run for 30 minutes. If the powershell script runs for long time, would it get stuck? The script completes sometimes, but sometimes, it is just postprocessing.

    param( $AcctName, $OwnerName)
    Import-Module ActiveDirectory
    $ADUser = Get-ADUser -LDAPFilter "(sAMAccountName=$AcctName)" -SearchBase "OUpath" -Server "dcname"
    while ($ADUser -eq $Null){

    Start-Sleep -Second 180
    $ADUser = Get-ADUser -LDAPFilter "(sAMAccountName=$AcctName)" -SearchBase "OUpath" -Server "dcname"

    }
    If($ADUser -ne $Null)
    {
    Start-Sleep -Second 360
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
    Set-mailbox $AcctName -Type Shared
    Add-MailboxPermission -Identity $AcctName -User $OwnerName -AccessRights 'FullAccess'
    }

    Tuesday, April 8, 2014 11:00 PM

Answers

  • It looks like if for some reason the account doesn't exist and is never created, your script will loop forever. Is that what you intend? If not, you probably want a counter and limit comparison on the counter in your while condition.

    Another option would be to detect that the mailbox has been created by flowing the email address or something that Exchange generates from AD back to the FIM Service. Use the data that arrives in the FIM Service to trigger a Set / Transition In MPR / Workflow that contains your PowerShell to grant permissions.

    Rex

    • Proposed as answer by Mike Crowley Tuesday, August 5, 2014 1:59 AM
    • Marked as answer by fim_sc Tuesday, August 5, 2014 1:03 PM
    Saturday, April 12, 2014 12:05 AM
  • Another option is to use a Management Agent instead to give the state based a retries for "free"; you could use either Microsoft PowerShell MA or mine (http://blog.goverco.com/p/powershell-management-agent.html)

    I have some scripts that handle Exchange mailbox creation - I can post them for download in the near future (was going to blog about it anyways)


    Regards, Soren Granfeldt
    blog is at http://blog.goverco.com | facebook https://www.facebook.com/TheIdentityManagementExplorer | twitter at https://twitter.com/#!/MrGranfeldt

    • Proposed as answer by Mike Crowley Tuesday, August 5, 2014 1:59 AM
    • Marked as answer by fim_sc Tuesday, August 5, 2014 1:03 PM
    Saturday, April 12, 2014 5:31 AM

All replies

  • Hi!

    First off this does not look like a clean solution but maybe it's what you need.

    As long as you running is as a "Action" Workflow FIM will not stop the script.

    Authorization WF should not run stuff like this.

    /Robert


    • Edited by Robert Kielén Thursday, April 10, 2014 7:48 PM correction
    Thursday, April 10, 2014 7:47 PM
  • It looks like if for some reason the account doesn't exist and is never created, your script will loop forever. Is that what you intend? If not, you probably want a counter and limit comparison on the counter in your while condition.

    Another option would be to detect that the mailbox has been created by flowing the email address or something that Exchange generates from AD back to the FIM Service. Use the data that arrives in the FIM Service to trigger a Set / Transition In MPR / Workflow that contains your PowerShell to grant permissions.

    Rex

    • Proposed as answer by Mike Crowley Tuesday, August 5, 2014 1:59 AM
    • Marked as answer by fim_sc Tuesday, August 5, 2014 1:03 PM
    Saturday, April 12, 2014 12:05 AM
  • Another option is to use a Management Agent instead to give the state based a retries for "free"; you could use either Microsoft PowerShell MA or mine (http://blog.goverco.com/p/powershell-management-agent.html)

    I have some scripts that handle Exchange mailbox creation - I can post them for download in the near future (was going to blog about it anyways)


    Regards, Soren Granfeldt
    blog is at http://blog.goverco.com | facebook https://www.facebook.com/TheIdentityManagementExplorer | twitter at https://twitter.com/#!/MrGranfeldt

    • Proposed as answer by Mike Crowley Tuesday, August 5, 2014 1:59 AM
    • Marked as answer by fim_sc Tuesday, August 5, 2014 1:03 PM
    Saturday, April 12, 2014 5:31 AM