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