将CMD脚本转换为Powershell脚本 [英] Converting CMD script to Powershell script

查看:722
本文介绍了将CMD脚本转换为Powershell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个CMD脚本,我需要转换为PowerShell,以便每次Azure AD用户登录到注册Intune的Azure AD加入的Windows 10设备时运行它:

I have this CMD script that I need to convert to PowerShell in order to have it run each time an Azure AD user signs in to an Azure AD joined Windows 10 device enrolled in Intune:

@powershell -NoProfile -ExecutionPolicy Bypass -Command" iex((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" &安培;&安培; SET PATH =%PATH%;%ALLUSERSPROFILE%\ chocolatey\bin

choco install logdna-agent -y

logdna-agent -k [masked]

logdna-agent -d%USERPROFILE%\ AppData \ LocalLow \ Kindred \ Kindred Pilot \LOGS

logdna-agent -t unity

nssm start logdna-agent

@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
choco install logdna-agent -y
logdna-agent -k [masked]
logdna-agent -d %USERPROFILE%\AppData\LocalLow\Kindred\Kindred Pilot\LOGS
logdna-agent -t unity
nssm start logdna-agent

我遇到了很多问题:


  1. 在PowerShell脚本中放置ExecutionPolicy Bypass为时已晚,因为需要首先绕过ExecutionPolicy才能在第一时间运行脚本。我很难过这个。目前,我在PowerShell中运行脚本之前手动绕过
    ExecutionPolicy,因为我仍然只是在使用Intune将脚本部署到客户端之前首先让脚本在PowerShell中工作。 / li>
  2. PowerShell不理解&& 。我在另一个论坛上看到,
    - 和是PowerShell的CMD版本&& ,但它不起作用。那么如何设置
    iex 命令调用的对象下载路径?
  3. 对于其他命令我已成功运行它们使用  cmd.exe / c ,然后使用引号中的命令。但是,未遵守变量  %USERPROFILE%。运行这些命令后
    结果的logdna.conf文件显示路径为  C:\\Users \\Test
    - 显然,这根本不是正确的道路。首先,它使用
    测试用户
    配置文件(我在测试计算机上创建的第一个管理员配置文件)而不是我登录的用户。其次,它忽略了其余的路径。
  1. Putting the ExecutionPolicy Bypass in the PowerShell script itself is too late, because the ExecutionPolicy needs to be bypassed first in order to even run the script in the first place. I'm stumped on this one. For the time being, I'm manually bypassing the ExecutionPolicy before running the script in PowerShell, since I'm still just troubleshooting getting the script to work in PowerShell in the first place before deploying it to clients using Intune.
  2. PowerShell doesn't understand &&. I have read in another forum that -and is PowerShell's version of CMD's && but it doesn't work. So how do I set the path for the download of that object invoked by the iex command?
  3. For the remainder of the commands I have successfully gotten them to run by using cmd.exe /c followed by the command in quotes. However, the variable %USERPROFILE% is not being obeyed. The logdna.conf file that results following the running of these commands shows a path of C:\\Users\\Test - That is not the correct path at all, obviously. First, it's using the Test User profile (the first admin profile I created on my test machine) instead of the user I'm logged in as. Second, it is omitting the rest of the path.

非常感谢能够帮助我解决这个问题的任何人。

Thank you so much to anyone who can help me get this sorted out.

推荐答案

您好KashiKindred,

Hi KashiKindred,

请尝试以下脚本。它对我有用。如果您还有其他问题,请告诉我们:

Please try out the below script. it worked for me. Let me know if you have any more questions:

iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) ; if (


?){


env:path =
env:path =


这篇关于将CMD脚本转换为Powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆