powershellbatch-filevbscriptdeprecatedelevation

Microsoft deprecating use of vbs commonly used to elevate batch script, while also defaulting powershell's execution policy to restricted


So Microsoft is deprecating the use of .vbs by 2027 to elevate batch files such as this (although fully updated windows 10 and 11 machines still run it until 2027):

    setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > %temp%\OEgetPrivileges.vbs" 
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs" 
"%temp%\OEgetPrivileges.vbs" 
exit /B 

Article for reference:

https://techcommunity.microsoft.com/blog/windows-itpro-blog/vbscript-deprecation-timelines-and-next-steps/4148301

Their answer is to "migrate to powershell" However, Microsoft also set the default PowerShell execution policy to restricted, which means using an elevated batch file to change PowerShell executionpolicy and run a PowerShell script that performs administrative functions will also soon stop working unless you manually change the setting.

What working solution has Microsoft given that actually works to run a powershell script with administrative rights? or have any of you found a work around for this upcoming event? I'm talking about right-click "Run with powershell" or executing a powershell script on a batch of computers... simplified options to use in scripts. It feels like they they're just closing doors without providing an exit, or I need to be enlightened by something I don't know.


Solution


  • As an aside:

    Microsoft also set the default PowerShell execution policy to Restricted