Powershell Diffuser Destroys Variable

The argument Split-Pathbelow is wrong and should be $delZipExe.
This makes the hash $delZipCmdzero.
I would expect the value WorkingDirectoryto be set by nothing in the hash $delZipCmd.

Why is this happening?

Set-StrictMode -Version latest
$delZipExe = '\\servername\ziptools\SP3DDeliverZips.exe'
$delZipDest = "D:\"
$delZipArgs = @( '/execute',
                 '/source', '/RAD ', '/debugpdb', '/wait'
               )
$delZipCmd = @{ FilePath = $delZipExe;
                ArgumentList = $delZipArgs;
                NoNewWindow = $true;
                WorkingDirectory = (Split-Path $delZipCmd);   # <== should be $delZipExe
                Wait = $true;
              }
$delZipCmd | ft
+4
source share
1 answer

Since checking the argument of the parameter on Split-Pathcauses a final error when constructing the hash table, the whole expression is terminated.

You can isolate the operator Split-Pathin a subexpression ( $()) to avoid this:

$delZipCmd = @{ 
    FilePath = $delZipExe;
    ArgumentList = $delZipArgs;
    NoNewWindow = $true;
    WorkingDirectory = $(Split-Path $delZipCmd);   # <== notice the $
    Wait = $true;
}
+4
source

Source: https://habr.com/ru/post/1661617/


All Articles