0

I'm trying to import a powershell script to use its function using python but the syntax I use seems to be off.

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

Following thses instructions : How to run a Powershell function through a Python script

The error :

. .\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

Basically its this script but I renamed its function: https://github.com/PowerShellEmpire/PowerTools/blob/master/PowerView/powerview.ps1

Any ideas ?

EDIT:

The function is working when manually imported and launched from 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
2
  • Does the code (the command contents) run in PowerShell terminal/ISE? Commented Feb 21, 2017 at 19:03
  • Yes, edited question with proof Commented Feb 21, 2017 at 19:09

1 Answer 1

0

Fixed my problem using another approach :

p = subprocess.Popen([r'powershell.exe',
                  '. .\powerview.ps1',
                  '; & Invoke-CustomShareFinder'])
p.communicate()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.