2016-12-12 84 views
0

我想導入一個模塊然後執行它。提供的參數不被識別?

如果我在PowerShell提示中這樣做,它的工作原理。

. "Z:\shm\Invoke-Runas.ps1" 
Invoke-Runas -User a -Password a -Binary C:\Windows\System32\cmd.exe -LoginType 0x1 

但是,如果我用一個襯墊,我得到了一個錯誤:

powershell -ep bypass . "Z:\shm\Invoke-Runas.ps1" ; Invoke-Runas -User a -Password a -Binary C:\Windows\System32\cmd.exe -LoginType 0x1 

Invoke-Runas : A parameter cannot be found that matches parameter name 'LoginTy 
pe'. 
At line:1 char:108 
+ . Z:\shm\Invoke-Runas.ps1 ; Invoke-Runas -User a -Password a -Binary C:\Windo 
ws\System32\cmd.exe -LoginType <<<< 0x1 
    + CategoryInfo   : InvalidArgument: (:) [Invoke-Runas], ParameterBi 
    ndingException 
    + FullyQualifiedErrorId : NamedParameterNotFound,Invoke-Runas 

它看起來像以前的命令吃了所有的參數,是我錯了嗎?

The source code is here

+0

是的,它從字面上吃了所有的參數。 :)把它們放在一個ps1文件中並觸發它;這比從控制檯處理要容易得多。 –

+0

@RanadipDutta所以沒有辦法解決它? – daisy

+0

作爲一個班輪?你可以有一個ps1文件,在那裏你可以做這個操作;如果你仍然希望將它作爲一個班輪,那麼讓我在這段時間內努力。然後我會回覆你 –

回答

0

嘗試在一個腳本塊包圍它,然後用符號運行命令前調用它。

powershell -ep bypass -command & {. "Z:\shm\Invoke-Runas.ps1" ; Invoke-Runas -User a -Password a -Binary C:\Windows\System32\cmd.exe -LoginType 0x1}