locked
Invoke-expression -command runas and calling script RRS feed

  • Question

  • Hello,

    i am trying  to create GUI powershell.

    When you clic in linklabel, 
    you Calling other script  with parameter "Runas".

    My problem is that I get an error when my other script have finished running
    and i dont have my result 

    ###My Error

    Invoke-Expression : Impossible de trouver un paramètre positionnel acceptant

    l'argument «System.Object[]».

    Au caractère C:\Users\aam96\Desktop\powershell\GUI Powershell.ps1:60 : 24

    + $LinkLabel.Add_Click( {Invoke-expression -command Runas ( Invoke-command

    -filepa ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    ~~~

        + CategoryInfo          : InvalidArgument : (:) [Invoke-Expression], Param

       eterBindingException

        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell

       .Commands.InvokeExpressionCommand

    #Label Position  Comparer deux utilisateurs et identifier les groupes d'accès commun  
    $Label = New-Object System.Windows.Forms.Label
    $Label.Text = "Comparer les 'Groupmembers'" 
    $Label.Location  = New-Object System.Drawing.Point(0,45)
    $Label.AutoSize = $true
    $main_form.Controls.Add($Label)
    
    $LinkLabel = New-Object System.Windows.Forms.LinkLabel 
    $LinkLabel.Location = New-Object System.Drawing.Size(0,60) 
    $LinkLabel.Size = New-Object System.Drawing.Size(150,20) 
    $LinkLabel.LinkColor = "Blue" 
    $LinkLabel.ActiveLinkColor = "Green" 
    $LinkLabel.Text = "Activate Identical Groupmembers" 
    $LinkLabel.Add_Click( {Invoke-expression -command Runas ( Invoke-command -filepath  'C:\Users\Boby\Desktop\powershell\Comparaison groupmember user.ps1' -computername $DC -ErrorAction SilentlyContinue) } ) 
    $main_form.Controls.Add($LinkLabel)

    Monday, January 14, 2019 4:13 PM

Answers

  • thank you for your anwser  JRV

    finaly i am using  this command

    $LinkLabel.Add_Click( {Start-Process powershell.exe -Verb Runas '&  C:\Users\%username%\Desktop\powershell\test1.ps1'})

    for this moment i dont have get error



    • Marked as answer by fnolin Monday, January 14, 2019 7:12 PM
    • Edited by fnolin Monday, January 14, 2019 7:35 PM finaly i need adding -verb Runas
    Monday, January 14, 2019 7:12 PM

All replies

  • You have to assign the results to a variable or a control.

    You cannot run a PowerShell command using "RunAs" which is a utility that only runs programs and not PS code.  Also RunAs requires other parameters which are missing.


    \_(ツ)_/

    Monday, January 14, 2019 5:19 PM
  • thank you for your anwser  JRV

    finaly i am using  this command

    $LinkLabel.Add_Click( {Start-Process powershell.exe -Verb Runas '&  C:\Users\%username%\Desktop\powershell\test1.ps1'})

    for this moment i dont have get error



    • Marked as answer by fnolin Monday, January 14, 2019 7:12 PM
    • Edited by fnolin Monday, January 14, 2019 7:35 PM finaly i need adding -verb Runas
    Monday, January 14, 2019 7:12 PM
  • For that you do not need to use Start-Process.  Just call the script.

    $LinkLabel.Add_Click({
        $results = C:\Users\Boby\Desktop\powershell\'Comparaison groupmember user'.ps1
    })
    

    It is a very bad idea to use spaces in script names.  A better name would be:

    Compare-GroupMemberUser.ps1

    which more closely matches the PS required naming conventions of verb-noun.


    \_(ツ)_/

    Monday, January 14, 2019 7:39 PM