This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PowerShellComponent - Execute CommandLine

Hello,

I need add some logic in the designer process  to trigger the following PowerShell commands,(there is already step to enable) but need to pass the userid/password as below to the QAS command.

 

Can anyone help how to pass the parameters..

 

Regards

Padma

Parents
  • Hi Padma,

    Here's an example of a PoSh script (defined as the Script parameter of the PowerShellComponent):

    Dim script As New StringBuilder()
    script.AppendLine( _
    String.Format( _
    "$$cred = New-Object System.Management.Automation.PSCredential (""{0}"", (ConvertTo-SecureString ""{1}""
    –AsPlainText -Force))", _
    $FK(UID_ADSContainer).FK(Ident_Domain).LDAPLogin$, _
    $FK(UID_ADSContainer).FK(Ident_Domain).LDAPLoginPassword$))
    script.AppendLine( _
    String.Format( _
    "$$session = New-PSSession -Configurationname Microsoft.Exchange –ConnectionUri http://{0}/PowerShell -
    Credential $$cred -Authentication Kerberos", _
    $FK(UID_ADSContainer).FK(Ident_Domain).FK(UID_Ex2KGatewayServer).FK(UID_Hardware)
    .DNSHostName$))
    script.AppendLine("Import-PsSession $$session")
    script.AppendLine("Import-Module activedirectory")
    script.AppendLine(String.Format("$$user2Find = ""{0}""", $SAMAccountName$))
    script.AppendLine("$$user = Get-ADUser $$user2Find -Properties mail")
    script.AppendLine("[string]$$user.mail")
    script.AppendLine("Remove-PSSession $$session")
    Value = script.ToString()

    You can see that the commands are using String.Format to replace values in the strings with parameter values that happen to be accessible in the context of the run - it's running against the table ADSAccount.

    Since the parameters do not allow/support additional parameters I would be inclined to use the 'Pre-script for generating' and in there create some 'parameters' as follows:

    values("param1") = <something>
    values("param2") = <something>
    etc.

    Then in your Script parameter you can use these parameters by referencing:

    values("param1").ToString
    etc.

    Hope that helps,

    Barry.
Reply
  • Hi Padma,

    Here's an example of a PoSh script (defined as the Script parameter of the PowerShellComponent):

    Dim script As New StringBuilder()
    script.AppendLine( _
    String.Format( _
    "$$cred = New-Object System.Management.Automation.PSCredential (""{0}"", (ConvertTo-SecureString ""{1}""
    –AsPlainText -Force))", _
    $FK(UID_ADSContainer).FK(Ident_Domain).LDAPLogin$, _
    $FK(UID_ADSContainer).FK(Ident_Domain).LDAPLoginPassword$))
    script.AppendLine( _
    String.Format( _
    "$$session = New-PSSession -Configurationname Microsoft.Exchange –ConnectionUri http://{0}/PowerShell -
    Credential $$cred -Authentication Kerberos", _
    $FK(UID_ADSContainer).FK(Ident_Domain).FK(UID_Ex2KGatewayServer).FK(UID_Hardware)
    .DNSHostName$))
    script.AppendLine("Import-PsSession $$session")
    script.AppendLine("Import-Module activedirectory")
    script.AppendLine(String.Format("$$user2Find = ""{0}""", $SAMAccountName$))
    script.AppendLine("$$user = Get-ADUser $$user2Find -Properties mail")
    script.AppendLine("[string]$$user.mail")
    script.AppendLine("Remove-PSSession $$session")
    Value = script.ToString()

    You can see that the commands are using String.Format to replace values in the strings with parameter values that happen to be accessible in the context of the run - it's running against the table ADSAccount.

    Since the parameters do not allow/support additional parameters I would be inclined to use the 'Pre-script for generating' and in there create some 'parameters' as follows:

    values("param1") = <something>
    values("param2") = <something>
    etc.

    Then in your Script parameter you can use these parameters by referencing:

    values("param1").ToString
    etc.

    Hope that helps,

    Barry.
Children
No Data