Run python script using Powershell loop...

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

Try use python3 <filepath.py>.

python3 .\zerologon_tester.py

Many thanks for your reply,

I found the following worked ok…

import-module activedirectory
$env:PATH=
$env:Path=";C:\Users\username\AppData\Local\Programs\Python\Python38-32"
$env:PATHEXT += ";.py";
$PyProg = 'C:\Users\username\Documents\Scripts\Test-ZeroLogon\zerologon_tester.py'
$dchostname = get-addomaincontroller -filter * | select-object name,ipv4address
foreach ($dc in $dchostname){
write-host 'test-zerologon.py'$dc.name$dc.ipv4address
$HN = $dc.name
$IP = $dc.ipv4address
python $PyProg $HN $IP
}

However I am now stumped as to output the returning text from the Python script

Any ideas on how I can do this?

 

 

Thanks

Are you referring to capture the output ? you can save it in a variable like $r = python sample.py.
You can even capture the output from foreach like below

$r = foreach($t in $List){
#WhateverCode
}