S
S
semen79072019-12-13 08:32:51
Python
semen7907, 2019-12-13 08:32:51

powershell request from python?

Tell me how can I execute this query in one line or in two lines
If I use

str = os.system("powershell Get-ADUser -filter {name -like 'Фамилия Имя'} ")
then it gives me information, but I need to write it to a file
. If I do this, then it works in powershell in two lines, but not from python ..
$GFile = "C:\Users\result.txt" 
Get-ADUser -filter {name -like 'Фамилия Имя'} | Out-File $GFile -encoding Unicode

str = os.system("powershell $GFile = 'C:/Users/result.txt' Get-ADUser -filter {name -like 'Фамилия Имя'} | Out-File $GFile -encoding Unicode}")

Error:
'Out-File' is not recognized as an internal or external
command, operable program, or batch file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2019-12-13
kuzmin @sergueik

pass in quotation marks, -command " & { #{script} } "
for example

powershell.exe -command "& {get-childitem -path '.' | select-object -first 1 | format-list }"


    Directory: C:\Users\Serguei



Name           : .cache
...

or through-file "#{script_filepath}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question