Challenges/issue at the customization section while creating image template in the Azure

Varma 1,495 Reputation points
2024-02-04T11:22:35.8033333+00:00

I am using image template to creat the image and during creation of image template in th custamizations section. User's image

I have added powershell command for each set of commands below. I have added PowerShell command for each set of commands below. ****PowerShell command 1: **** New-Item -Type Directory -Path 'c:' -Name Java, invoke-webrequest -uri 'https://download.oracle.com/java/21/latest/jdk-21_windows-x64_bin.msi' -OutFile 'c:\temp\jdk-21_windows-x64_bin.msi', copy-item 'c:\temp\jdk-21_windows-x64_bin.msi' -Destination 'c:\temp' ****PowerShell Command 2: **** Start-Process -FilePath 'c:\temp\jdk-21_windows-x64_bin.msi' PowerShell command 3: Set the name and value of the environment variable $variableName = "JAVA_HOME" $variableValue = "C:\Program Files\Java\jdk-21\bin" Use [System.Environment]::SetEnvironmentVariable method to set the environment variable [System.Environment]::SetEnvironmentVariable($variableName, $variableValue, [System.EnvironmentVariableTarget]::Machine) Display a message indicating that the variable has been added Write-Host "Environment variable $variableName set to $variableValue" ****PowerShell command 4: **** New-Item -Type Directory -Path 'c:' -Name Python, invoke-webrequest -uri 'https://www.python.org/ftp/python/3.12.1/python-3.12.1-amd64.exe' -OutFile 'c:\temp\python-3.12.1-amd64.exe', copy-item 'c:\temp\python-3.12.1-amd64.exe' -Destination 'c:\temp' PowerShell command5: Start-Process -FilePath 'c:\temp\python-3.12.1-amd64.exei' I only see folders and .exe and MSI files copied in to the target VM but not executed .msi and .exe file that means only PowerShell command 1 and 4 worked but other commands not worked, Please suggest fix for this. I have not seen any error after image template got created. what could be the wrong with other commands You can see start process working inside VM which after I have tested User's image

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,015 questions
0 comments No comments
{count} votes

Accepted answer
  1. Timmy Malmgren 1,521 Reputation points
    2024-02-04T16:14:10.59+00:00

    Hello Varma

    I modified it a little and tested it both locally and on an Image in my own gallery. I added some comment and explanation in the code, feel free to remove them or modify them to your liking :)
    Don't hesitate to ask if you run into trouble with it.

    #Creates the directory Java in C:
    New-Item -ItemType Directory -Path "c:\Java" 
    
    #Downloads the Java MSI file, I changed from Invoke-Webrequest to Invoke-RestMethod to ensure it waits for the download to complete before moving on
    Invoke-RestMethod -uri "https://download.oracle.com/java/21/latest/jdk-21_windows-x64_bin.msi" -OutFile "c:\Java\jdk-21_windows-x64_bin.msi"
    
    #Starts the installation, also added a Wait command here to ensure the installation is complete before moving on to next step, added /quiet to ensure no user interaction is needed.
    Start-Process msiexec.exe -Wait -ArgumentList "/I c:\Java\jdk-21_windows-x64_bin.msi /quiet"
    
    #Shortened the environmental command by using the command below, it creates a Environmental variable called #JAVA_HOME with the value of 'C:\Program Files\Java\jdk-21\bin'
    #$Env:JAVA_HOME = 'C:\Program Files\Java\jdk-21\bin'
    
    #Added back to set the variable to system instead of user
    [System.Environment]::SetEnvironmentVariable("JAVA_HOME","C:\Program Files\Java\jdk-21\bin","Machine")
    
    #Writes out the content of the environmental variable JAVA_HOME
    Write-Host $Env:JAVA_HOME "has been added to the environmental variable JAVA_HOME"
    
    #Creates the directory Python in C:
    New-Item -ItemType Directory -Path "c:\Python"
    
    #Same download procedure as with java but for Python
    Invoke-RestMethod -uri "https://www.python.org/ftp/python/3.12.1/python-3.12.1-amd64.exe" -OutFile "c:\Python\python-3.12.1-amd64.exe"
    
    #Same installation procedure as with java but EXE file instead and added /silent to ensure no user interaction is needed. Added the InstallAllUser=1 to ensure its installed for all users.
    Start-Process -Wait -FilePath "c:\Python\python-3.12.1-amd64.exe" "/quiet InstallAllUsers=1 PrependPath=1"
    

    Hope this is helpful Best Regards, Timmy Malmgren

    ---If the Answer is helpful, please click "Accept Answer" and upvote it as it helps others to find what they are looking for faster!


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.