Ar.Bazargani
Ar.Bazargani

Reputation: 13

PowerShell command not run via cmd script

Here see the script, the last command should works, i mean everything's ok and it works when i run in windows Powershell. But when i join that with 2 first commands which are bash scripts, the powershell's one won't run:

Net user administrator /active:yes

Net user administrator Hardware123

Set-LocalUser -Name "administrator" -PasswordNeverExpires 1

Upvotes: 0

Views: 797

Answers (1)

Jawad
Jawad

Reputation: 11364

If you want to call powershell commands from a cmd / batch file, use the following syntax. You have to call powershell to be able to run powershell commands,

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

This is with assumption that you already have admin access to perform the above script.

You can also run multiple commands with powershell.exe if you intend to use variables,

powershell -Command "$local = Get-LocalUser; $local.Name; if ('Administrator' -in $local.Name) { 'Do Something' } else { 'Administrator Not Found' }"

Upvotes: 0

Related Questions