# If the script does not work due to policy restrictions, you can change the Windows policy for the current session (not permanently): # Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process # Function to retrieve the Windows product key function Get-WindowsProductKey { $path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" $key = Get-ItemProperty -Path $path $productKey = $key.BackupProductKeyDefault if ($productKey) { Write-Output "Your Windows Product Key: $productKey" } else { Write-Output "Could not retrieve the product key." } } # Check the current execution policy and notify the user if it might block the script if ((Get-ExecutionPolicy -Scope Process) -notin @("RemoteSigned", "Bypass")) { Write-Output "The current execution policy might block the script. Running the following command allows it for this session only:" Write-Output "`nSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process`n" Write-Output "Re-run the script after running the above command if necessary." } else { # Run the product key retrieval function Get-WindowsProductKey }