Powershell command to Python



试图让下面的代码运行,但我努力寻找下面的高亮部分的解决方案,它不喜欢代码的'文件'部分。谢谢你的帮助。

import subprocess    
def getaclsec():
pscommand = '$file1 = Import-Csv -Path "C:\Source\testpath.csv" ForEach ($file in $file1) {$infoSec = Get-Acl -Path $file.FullPAth $infoSec.Access | Select @{l='File';e={$file.FullPath}},* | Export-Csv -Path "C:\Source\newTestPathSect.csv" -Append}'
process=subprocess.Popen(["powershell","& {" + pscommand + "}"],stdout=subprocess.PIPE);
getaclsec()

答案:

import subprocess    
def getaclsec():
pscommand = '$file1 = Import-Csv -Path "C:\Source\testpath.csv"; ForEach ($file in $file1) {$infoSec = Get-Acl -Path $file.FullPAth; $infoSec.Access | Select @{l="File";e={$file.FullPath}},* | Export-Csv -Path "C:\Source\newTestPathSect.csv" -Append}'
process=subprocess.Popen(["powershell","& {" + pscommand + "}"],stdout=subprocess.PIPE);
getaclsec()

最新更新