none
Start-Process- A positional parameter cannot be found that accepts argument 'powershell.exe' RRS feed

  • General discussion

  • I am new to PowerShell scripting. That being said, I have been teaching myself how to write scripts, and this one is just driving me crazy!!!! I am trying to run this script so that PoweShell opens as our sub-admin account so that I can run my other scripts to make life easier for us. If anyone could help me out with this I would really appreciate it. Thanks in advance!!

    Also I have looked all through the threads on here, and have tried literally everything!! I actually found this script in the Script Center and thought "This is exactly what I need!" 

    Comp:

    Windows 7 Pro 64 bit. Running on domain.

    Powershell v4.0- Just installed (Cant find .exe file in system32 for v4.0 just v1.0)

    Script:

    Add-Type -AssemblyName System.Windows.Forms

    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.Title = "Run Powershell Script"
    $OpenFileDialog.InitialDirectory = $([Environment]::GetFolderPath("Desktop"))
    $OpenFileDialog.Filter = "Windows PowerShell Scripts (*.ps1)| *.ps1"
    $OpenFileDialog.ShowHelp = $True

    [void] $OpenFileDialog.ShowDialog()
    Start-Process "-NoNewWindow" powershell.exe -Credential $(Get-Credential) -ArgumentList "Start-Process C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Verb runAs $($OpenFileDialog.Filename)" 

    The script runs perfectly until it gets to here:

    [void] $OpenFileDialog.ShowDialog()
    Start-Process "-NoNewWindow" powershell.exe -Credential $(Get-Credential) -ArgumentList "Start-Process C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Verb runAs $($OpenFileDialog.Filename)" 

    The error its giving me is:

    cmdlet Get-Credential at command pipeline position 1
    Supply values for the following parameters:
    Start-Process : A positional parameter cannot be found that accepts argument 
    'powershell.exe'.At C:\Users\me\Desktop\Scripts\Company Information Monitor 
    Scripts\Misc Scripts\Run Script as Admin.ps1:10 char:1
    + Start-Process "-NoNewWindow" "powershell.exe" -Credential $(Get-Credential) 
    -Arg ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~
        + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterB 
       indingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell 
       .Commands.StartProcessCommand

    I have been trying to get this working all day with no success. Like I said I am currently teaching myself, the best way to learn is to reach out to others who are skilled and ask for advice!!

    Thanks,

    Owen



    Friday, July 10, 2015 6:52 PM

All replies

  • Try to change 
    Start-Process "-NoNewWindow" powershell.exe

     to 
    Start-Process powershell.exe -NoNewWindow

    Friday, July 10, 2015 8:03 PM
  • Leif-Arne Helland,

    Thanks for the reply! Still having issues unfortunately... I changed the script around a bit and it seems to be running but it doesn't do anything, it just hangs. I'll provide what it says after the script is done below. I'll also show changes I made in bold.

    Current Script:

    Add-Type -AssemblyName System.Windows.Forms

    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.Title = "Run Powershell Script"
    $OpenFileDialog.InitialDirectory = $([Environment]::GetFolderPath("Desktop"))
    $OpenFileDialog.Filter = "Windows PowerShell Scripts (*.ps1)| *.ps1"
    $OpenFileDialog.ShowHelp = $True

    [void] $OpenFileDialog.ShowDialog()
    "Start-Process powershell.exe -NoNewWindow -Credential $(Get-Credential)-ArgumentList Start-Process powershell.exe -Verb runAs $($OpenFileDialog.Filename)"

    When it hangs this is what it says:

    PS C:\Windows\system32> C:\Users\olowe\Desktop\Scripts\Company Information Monitor Scripts\Misc Scripts\Run Script as Admin.ps1
    cmdlet Get-Credential at command pipeline position 1
    Supply values for the following parameters:
    Start-Process powershell.exe -NoNewWindow -Credential System.Management.Automat
    ion.PSCredential-ArgumentList Start-Process powershell.exe -Verb runAs C:\Windo
    ws\Get-LastBootTime.ps1

    I moved the script to the C:/Windows folder to make it easier.

    Thanks for your suggestion, it looks like the script isn't showing any errors, but I'm not shown as sub admin and it doesn't prompt me for a computer name for LastBootTime.ps1.


    Friday, July 10, 2015 8:46 PM
  • Your quotes are in the wrong place.

    Add-Type -AssemblyName System.Windows.Forms
    
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.Title = "Run Powershell Script"
    $OpenFileDialog.InitialDirectory = $([Environment]::GetFolderPath("Desktop"))
    $OpenFileDialog.Filter = "Windows PowerShell Scripts (*.ps1)| *.ps1"
    $OpenFileDialog.ShowHelp = $True
    
    [void] $OpenFileDialog.ShowDialog()
    Start-Process powershell.exe -NoNewWindow -Credential $(Get-Credential)-ArgumentList "Start-Process powershell.exe -Verb runAs $($OpenFileDialog.Filename)"

    Friday, July 10, 2015 9:01 PM
  • Thanks!!!! That worked you are awesome!!
    Friday, July 10, 2015 9:33 PM
  • I don't think that will work....

    [void]$OpenFileDialog.ShowDialog()
    $splat = @{
    	FilePath = 'powershell.exe'
    	NoNewWindow = $true
    	Credential = Get-Credential
    	ArgumentList = "Start-Process powershell.exe -Verb runAs -ArgumentList $($OpenFileDialog.Filename)"
    }
    Start-Process @splat
    
    This format helps us to see mistakes and is easier to update.


    \_(ツ)_/

    Friday, July 10, 2015 9:38 PM
  • Note that you cannot use both -Verb and Credential in the same command.


    \_(ツ)_/

    Friday, July 10, 2015 9:41 PM