Run CMD within Powershell

Hi all, i need to run a cnd with parameter within a powershell script.
The syntax is:

“i:\something\quota_create_unity.cmd” -n %username%

variable %username% is passed by a csv

I’m using the syntax:
Start-Process -verb runas -filepath “I:\UOC Gestione Strutture Tecnologiche\Quota_Set\quota_create_unity.cmd”

but i can’t pass the properties, any suggestion?
Maybe I’m using a wrong Method?
Thanx

Could you please format your code as code using the preformatted text button ( </> )?

Thanks in advance.

Why do you have to run a CMD from a PowerShell script? I cannot imagine that there’s something you can do in CMD what you cannot do in pure PowerShell. You should migrate the CMD to PowerShell.

Regardless of that - the executable for a CMD would be C:\Windows\System32\cmd.exe. So the proper PowerShell command using Start-Process would be:

Start-Process -Verb RunAs -FilePath 'C:\Windows\System32\cmd.exe' -ArgumentList "/C 'I:\UOC Gestione Strutture Tecnologiche\Quota_Set\quota_create_unity.cmd' -n $ENV:USERNAME"

What do you mean by that? In CMD %username% is an environment variable representing the currently logged on user. The according PowerShell version would be $Env:USERNAME.

Hi Olaf nice to see you :smiley:
I find the solution:

$Username = 'Pallid'
$PSScriptRoot = “I:\UOC Gestione Strutture Tecnologiche\Quota_Set”

$arg = ("-n {0}" -f $Username)

$proc = Start-Process -FilePath "quota_create_unity.cmd" -WorkingDirectory $PSScriptRoot -ArgumentList $arg -Wait -PassThru

The %username% is the environment in the cmd, non it isn’t the current logged user, but a username that changes from time to time.
This script set the hard quota on NAS and changes from user to user

For a default Windows installation that’s wrong.

The CMD set only the Hardquota for The Homedir of a set User in a csv file.
No Installation and nothing Wrong
G