Hi, if you don't want to / cannot expose your VM to the Internet (so you can connect to it from your machine) and if we exclude options like P2S VPN between your machine an Azure VNet, where your VM gets deployed, there are three options:
1. You can use a Custom script VM Extension with either a shell or a PowerShell script. The script itself could either be provided in-line or referenced via a public URI. VM Extensions are Azure resources, so they can be created programmatically in both imperative (script) and declarative (ARM JSON, Bicep, Terraform) way. More info:
https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows2. You could use Run Command feature, more info here:
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/run-command3. You could use a proven Config management tool like Chef, Puppet, Ansible, etc. but this requires more infrastructure, and it is more complex to implement.