I want to use PowerShell to automate diskpart.exe, but the script arguments that PowerShell builds are seen as invalid. For example, the trivial diskpart script below works as expected:
$diskDetailsDPCom=@(
"select disk 0",
"detail disk",
"exit"
)
$diskDetailsDPCom | diskpart
But when I try to build the “select disk” command by concatenating a variable or literal “0”, then diskpart fails with The arguments specified for this command are not valid.:
$diskDetailsDPCom=@(
"select disk " + "0",
"detail disk",
"exit"
)
$diskDetailsDPCom | diskpart
What is going on here, and how might I proceed?
"select disk " + “0”->("select disk " + “0”)