2017-02-21 28 views
0

私はpythonを使って関数を使うためにpowershellスクリプトをインポートしようとしていますが、私が使っている構文はオフになっているようです。 thsesの指示に従いpythonからpowershell関数を実行していません

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

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

任意のアイデア?

EDIT:手動でインポートおよび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() 
関連する問題