How To Execute PowerShell Script with Dynamic Variables

Hello everyone,

I have two dynamic variables, I want to use invoke powershell activity as an anternative way of active directory acitivities how can I run this script in uipath invoke powershell activity?
Do you have any idea?

New-ADGroup -Name “variable1” -SamAccountName variable1 -GroupCategory Security -GroupScope Global -DisplayName “variable1” -Path “OU=HQ_Units,OU=Permission_Groups,OU=Groups,DC=asdf,DC=local” -Description “Test”

Add-AdGroupMember -Identity “variable1” –Members variable2

Add-ADPrincipalGroupMembership -Identity variable1 -MemberOf variable2

Set-ADGroup -Identity “variable1” -Replace @{extensionAttribute15=“123”}

Thanks in advance

Hi,

How about to use string.format as the following.

First, create text file for the script as the followng

New-ADGroup -Name "{0}" -SamAccountName {0} -GroupCategory Security -GroupScope Global -DisplayName "{0}" -Path "OU=HQ_Units,OU=Permission_Groups,OU=Groups,DC=asdf,DC=local" -Description "Test"

Add-AdGroupMember -Identity {0} –Members {1}

Add-ADPrincipalGroupMembership -Identity variable1 -MemberOf {1}

Set-ADGroup -Identity "{0}" -Replace @{{extensionAttribute15="123"}}

Set {0} or {1} to replace content of variable. And escape { and } character like {{ and }}.

script.txt (383 Bytes)

Then use string.Format(strPsScript,{variable1,variable2}) as the following.

image

Regards,

You can also use the PowerShellVariables property to pass your variables to the PS-script.

image

thank you very much

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