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
Community
  • 1
  • 1
Guillaume Caillé
  • 393
  • 2
  • 6
  • 20

1 Answers1

0

Fixed my problem using another approach :

p = subprocess.Popen([r'powershell.exe',
                  '. .\powerview.ps1',
                  '; & Invoke-CustomShareFinder'])
p.communicate()
Guillaume Caillé
  • 393
  • 2
  • 6
  • 20