none
Reformatting CMD script as PowerShell RRS feed

  • Question

  • When I edited my post in the PowerShell forum, it said it was marked as spam and to post it here. So here it is:

    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\binchoco install logdna-agent -ylogdna-agent -k b68259da5ed1de21fbb0574de1bda24elogdna-agent -d %USERPROFILE%\AppData\LocalLow\Kindred\Kindred Pilot\LOGSlogdna-agent -t unitynssm start logdna-agent

    I've run into a bunch of issues:

    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.

    Wednesday, February 27, 2019 7:18 PM

Answers