相关文章推荐
性感的酱牛肉  ·  如何通过浏览器返回按钮实现从独立Div编辑区 ...·  2 月前    · 
面冷心慈的绿茶  ·  透過 JavaScript 動態修改CSS ...·  3 周前    · 
没有腹肌的围巾  ·  Google試算表與Google App ...·  2 周前    · 
爱跑步的松鼠  ·  Remediate Passwords·  8 月前    · 
儒雅的椅子  ·  南京市人民政府·  1 年前    · 
任性的甜瓜  ·  MindMaster用例(.emmx)转Ex ...·  1 年前    · 
老实的橙子  ·  micpython ...·  1 年前    · 
独立的红豆  ·  沿着地铁去买房 沈阳地铁二号线北延线四站点考察报告·  1 年前    · 
Code  ›  Solved: LIVEcommunity - Powershell Script and XDR - LIVEcommunity - 529931
脚本
https://live.paloaltonetworks.com/t5/cortex-xdr-discussions/powershell-script-and-xdr/td-p/529931
聪明伶俐的脸盆
1 年前
Prisma Access Insights Discussions
Prisma Access for MSPs and Distributed Enterprises Discussions
Prisma Access Cloud Management Discussions
Prisma SD-WAN Discussions
Prisma SD-WAN CloudBlades Discussions
Prisma SD-WAN AIOps Discussions
Autonomous DEM Discussions

There is a PowerShell script that we would like to use within XDR. I understand that XDR currently is not able to run PowerShell scripts, the problem is I am not a coder. I have been trying to learn how to convert our script to Python but I am just about to give up.

In my research, I found some posts from users on various websites explaining that it is possible to run a PowerShell script with Python and I wondered if this could be a workaround?

import subprocess, sys
p = subprocess.Popen(["powershell.exe", 
              "C:\\Scripts\\PS-ScriptWeNeed.ps1"], 
              stdout=sys.stdout)
p.communicate()

The problem I see is that the assumption is you are running this script from your own host and directing Python to the path where the PowerShell script is located on your host, therefore, this is not possible unless all host already have this file located in the same file path on each host. If that is the case, any other work arounds?

If none of the above work, any chance anyone here could recommend a good resource that could help me with converting this script from PowerShell to Python?

@bbarmanroy sorry for the delayed response, drowning in work haha. Thank you for that suggestion! I was actually working on trying to get that done but just was not able to. I keep getting errors regarding the syntax somewhere in the script and just could not figure it out and finally gave up.

Decided it was better to just recreate the script in Python, so just bit the bullet and pulled an all-nighter trying to figure out how to get that done and it finally worked. Great learning experience but it did reinforce my original belief that coding is not for me lol.

Thank you again for trying to help!

@bbarmanroy sorry for the delayed response, drowning in work haha. Thank you for that suggestion! I was actually working on trying to get that done but just was not able to. I keep getting errors regarding the syntax somewhere in the script and just could not figure it out and finally gave up.

Decided it was better to just recreate the script in Python, so just bit the bullet and pulled an all-nighter trying to figure out how to get that done and it finally worked. Great learning experience but it did reinforce my original belief that coding is not for me lol.

Thank you again for trying to help!

import subprocess; process=subprocess.Popen(["powershell","& {" + pscommand + "}"],stdout=subprocess.PIPE); result=process.communicate()[0] print (result) windowsupdate()

Put all your PowerShell commands between the triple quotes in that big blank space. I haven't had issues with what PowerShell commands I can run. One thing to note is that you need to use forward slash's (/) if you're referencing a directory, otherwise XDR will have issues. Spent a few hours debugging before realizing that was the issue. Hope this helps!

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!

 
推荐文章
性感的酱牛肉  ·  如何通过浏览器返回按钮实现从独立Div编辑区返回表格记录视图
2 月前
面冷心慈的绿茶  ·  透過 JavaScript 動態修改CSS 樣式、屬性 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天
3 周前
没有腹肌的围巾  ·  Google試算表與Google App Script的自動化應用
2 周前
爱跑步的松鼠  ·  Remediate Passwords
8 月前
儒雅的椅子  ·  南京市人民政府
1 年前
任性的甜瓜  ·  MindMaster用例(.emmx)转Excel用例 - e2x工具使用说明-CSDN博客
1 年前
老实的橙子  ·  micpython esp32库包含了jason模块吗 - CSDN文库
1 年前
独立的红豆  ·  沿着地铁去买房 沈阳地铁二号线北延线四站点考察报告
1 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号