azure cli command to run the sysprep

Vedanth Pulipati 241 Reputation points

i am trying to run the sysprep before converting it into an image

i have used the following command for the sysprep

az vm run-command invoke --command-id RunPowerShellScript -g $resourceGroupName -n $serverName --scripts .\resources\win-vm\sysprep.ps1

in the file sysprep.ps1 consists the below command

C:\WINDOWS\system32\sysprep\sysprep.exe /generalize /shutdown /oobe

the below is the error i am facing

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,065 questions
{count} votes

1 additional answer

Sort by: Most helpful
  1. shiva patpi 13,131 Reputation points Microsoft Employee

    Hello @Vedanth Pulipati ,
    Can you try out Invoke-AzVMRunCommand ?
    Sample example:

    Invoke-AzVMRunCommand -ResourceGroupName syspredemo -VMName sysprepdemo -CommandId "RunPowerShellScript" -ScriptPath "C:\aks\date.ps1"


    Let me know if that helps !