我有这个powershell命令,它必须在powershell中作为管理员运行。我想作为管理员作为批处理文件运行。你能帮帮我吗?
Get -allusers ContentDeliveryManager ContentDeliveryManager foreach {AppxPackage "$($_.InstallLocation)\appxmanifest.xml“-DisableDevelopmentMode -register }
发布于 2021-05-21 03:55:52
你可以这样运行:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -Command ""& {Get-AppxPackage -allusers ContentDeliveryManager | foreach {Add-AppxPackage ""$($_.InstallLocation)\appxmanifest.xml"" -DisableDevelopmentMode -register }"" -Verb RunAs}"
更新
固定双引号
发布于 2021-05-21 06:12:23
为了避免双引号/双引号的问题,我建议您将命令放在script.ps1
中,然后执行以下命令:
PowerShell -windowstyle hidden -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -windowstyle hidden -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""YourScript.ps1""' -Verb RunAs}"
发布于 2021-05-21 11:59:53
试试这批
<# : batch script
@echo off
cd /D "%~dp0"
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
setlocal
cd %~dp0
powershell -executionpolicy remotesigned -Command "Invoke-Expression $([System.IO.File]::ReadAllText('%~f0'))"
endlocal
goto:eof
#>
# here write your powershell commands...
Get-AppxPackage -allusers ContentDeliveryManager | foreach {Add-AppxPackage "$($_.InstallLocation)\appxmanifest.xml" -DisableDevelopmentMode -register }
将其保存为.bat或.cmd并运行它。
https://stackoverflow.com/questions/67630567
复制相似问题