You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell命令与Bash脚本命令组合后无法执行问题咨询

Fixing Mixed CMD/PowerShell Command Execution Issues

Got it, let's break down why your combined script isn't working and walk through the solutions.

The Root Cause

Your first two commands (Net user ...) are CMD-native commands, while the third one (Set-LocalUser ...) is a PowerShell-exclusive cmdlet. If you're running all three in a .bat/.cmd script (or directly in a CMD window), the CMD interpreter doesn't understand PowerShell syntax—so it'll throw an error when it hits the Set-LocalUser line.

Solution 1: Wrap PowerShell Commands in CMD Scripts

If you want to keep using a CMD script, you can call PowerShell explicitly to run the third command. Use the powershell -Command parameter to pass the PowerShell cmdlet to the PowerShell interpreter:

Net user administrator /active:yes
Net user administrator Hardware123
powershell -Command "Set-LocalUser -Name 'administrator' -PasswordNeverExpires 1"

Note: We use single quotes inside the double quotes to avoid syntax conflicts in CMD.

For cleaner, more native execution, rewrite all commands using PowerShell's built-in local user management cmdlets. This avoids mixing interpreters entirely:

# Enable the administrator account
Enable-LocalUser -Name "administrator"

# Set the administrator password (convert plain text to secure string first)
$securePassword = ConvertTo-SecureString "Hardware123" -AsPlainText -Force
Set-LocalUser -Name "administrator" -Password $securePassword

# Set password to never expire
Set-LocalUser -Name "administrator" -PasswordNeverExpires $true

Save this as a .ps1 file, then right-click it and select "Run with PowerShell" (make sure you're running as an administrator).

Critical Note

All these commands require administrator privileges to run successfully. Whether you're using CMD or PowerShell, always launch the interpreter by right-clicking and selecting "Run as administrator"—otherwise you'll get permission denied errors.

内容的提问来源于stack exchange,提问作者Ar.Bazargani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 18:02:30