# This code requires Windows 10 professional/Enterprise or Windows Server 2016 $vmname = read-host "VMName" $key = read-host "Windows Key" Invoke-Command -VMName $vmname -ScriptBlock { param($key) Write-Verbose -Message "Attempting to inject Windows key: $key" Cscript.exe $env:SystemRoot\System32\slmgr.vbs -ipk $key Write-Verbose -Message "Attempting to activate Windows key" Cscript.exe $env:SystemRoot\System32\slmgr.vbs -ato } -ArgumentList $key