I don't understand why (
is missing?
if not exist ("C:\test") md "C:\test"
At line:1 char:3
if not exist ("C:\test") md "C:\test"
~
Missing '(' after 'if' in if statement.
CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : MissingOpenParenthesisInIfStatement
CodePudding user response:
Building on the helpful comments:
You're trying to use
cmd.exe
's syntax directly from PowerShell, which cannot work (given PowerShell's fundamentally different syntax) and causes the parsing error you saw.Use the PowerShell equivalent of your
cmd.exe
call, viaNew-Item
:
# Create directory C:\test or use a preexisting directory with that path
# (thanks to -Force).
# A DirectoryInfo object describing the directory is returned,
# which $null = ... discards.
$null = New-Item -Type Directory -Force C:\test