2017-02-21 105 views
0

我想导入PowerShell脚本来使用它的功能使用Python,但我使用的语法似乎是关闭的。从Python运行PowerShell功能不工作

p = subprocess.call(["C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", '-Command', '&{". .\powerview.ps1"; & Invoke-CustomShareFinder}']) 

继thses说明:How to run a Powershell function through a Python script

错误:

. .\powerview.ps1 
& : The term 'Invoke-CustomShareFinder' is not recognized as the name of a cmdlet, function, script file, or operable 
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 
At line:1 char:32 
+ &{". .\powerview.ps1"; & Invoke-CustomShareFinder} 
+       ~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : ObjectNotFound: (Invoke-CustomShareFinder:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

基本上它的这个剧本,但我改名为它的功能: https://github.com/PowerShellEmpire/PowerTools/blob/master/PowerView/powerview.ps1

任何想法?

编辑:

手动导入和PowerShell的推出时,此功能工作:

PS C:\Users\gcaille\Documents\my_program> . .\powerview.ps1 
PS C:\Users\gcaille\Documents\my_program> Invoke-CustomShareFinder 
\\server\ADMIN$   - Remote Admin 
\\server\C$  - Default share 
\\server\IPC$ - Remote IPC 
+0

代码是否(命令内容)在PowerShell终端/ ISE中运行? – wOxxOm

+0

是的,编辑问题与证明 –

回答

0

使用其他方法固定我的问题:

p = subprocess.Popen([r'powershell.exe', 
        '. .\powerview.ps1', 
        '; & Invoke-CustomShareFinder']) 
p.communicate()