PowerCLI

 View Only
  • 1.  Run python script using Powershell loop...

    Posted Oct 01, 2020 05:46 PM

    Hi,

    I need to run a Python Zerologon_tester.py script within a powershell script but have no idea how to do this

    The python script zerologon_tester.py uses the following syntax:

    .\zerologon_tester.py <DomainControllerHostname> <IP>

    I want to use a powershell script such as the following and add the domain hostname and IP address into the python script using variables for the syntax, something as follows:

    import-module activedirectory

    $env:PATHEXT += ";.py"

    $dchostname = get-addomaincontroller -filter * | select-object name,ipv4addpress

    foreach ($dc in $dchostname){

    .\zerologon_tester.py $dc.name $dc.ipv4address

    }

    I also need to make sure that the next execution only follows the completions of the preceding one

    Many thanks



  • 2.  RE: Run python script using Powershell loop...

    Posted Oct 01, 2020 06:05 PM

    Afaik, you can run any command in a PS script that you could run at a CMD prompt.

    So the code you show should work.

    What is the problem?
    Doesn't the PS script wait till the Phyton script completes?



  • 3.  RE: Run python script using Powershell loop...

    Posted Oct 01, 2020 06:27 PM

    Hi,

    The python script runs, however the variables do not get added to the .py script syntax

    Can I assume that this is not possible to mix Ps variables into a python script like this...

    .\zerologon_tester.py $dc.name $dc.ipv4address

    The error returned is from the Python script:

    Tests whether a domain controller is vulnerable to the zerologon attack. Does not attempt to make any changes.

    Note: dc-name should be the (NetBIOS) computer name of the domain controller.

    Usage: zerologon_tester.py <dc-name> <dc-ip>

    Thanks!



  • 4.  RE: Run python script using Powershell loop...

    Posted Oct 01, 2020 06:37 PM

    I personally never mixed PS and python, but this article seems to show how you can pass arguments
    How to: Pass Arguments to Python Script via Powershell - Stack Overflow (stackoverflow.com)



  • 5.  RE: Run python script using Powershell loop...

    Posted Oct 01, 2020 07:48 PM

    Hi,

    Thanks for the article it did help

    Also I did have a typo in one of my select objects

    The following script works fine,

    The next thing I would like to be able to do is pull the returning lines of output to either a .csv or .txt file

    'Success! DC can be fully compromised by a Zerologon attack.'

    or

    'Attack failed. Target is probably patched.'

    Any ideas on how I can do this?

    Many, many thanks again!



  • 6.  RE: Run python script using Powershell loop...
    Best Answer

    Posted Oct 01, 2020 07:56 PM

    Did you try like this?

    $result = python $PyProg $HN $IP


  • 7.  RE: Run python script using Powershell loop...

    Posted Oct 06, 2020 03:23 PM

    Thanks LucD