将双引号传递给命令

时间:2019-05-15 18:54:02

标签: powershell

无论何时在输入CSV文件中遇到值'NO_PERM'时,我都需要将两个双引号作为参数参数传递给pmrep assignpermission命令。由于某种原因,它无法正常工作,并且正在向命令发送空字符串。

$InputFile = Read-Host "Enter the Input File Name"
$CSVFile = Import-Csv "D:\$InputFile"
foreach ($Vals in $CSVFile) {
    $FolderName = $Vals.FOLDER_NAME
    $UserName = $Vals.USER_NAME
    $Permissions = $Vals.PERMISSIONS
    if ($Permissions -match "NO_PERM") {
        $Permissions1 = '""'
        Invoke-Command -ScriptBlock {
            & cmd.exe /c "D:\pmrep.exe AssignPermission"  -n "$FolderName" -g "$UserName" -p "$Permissions1" -o "Folder" -s "Native"
        }
    }
}

1 个答案:

答案 0 :(得分:0)

$InputFile = Read-Host "Enter the Input File Name"
$CSVFile = Import-Csv "D:\$InputFile"
foreach ($Vals in $CSVFile) {
    $FolderName = $Vals.FOLDER_NAME
    $UserName = $Vals.USER_NAME
    $Permissions = $Vals.PERMISSIONS
    if ($Permissions -match "NO_PERM") {
        $Permissions1 = '""'
        & D:\pmrep.exe AssignPermission  -n "$FolderName" -g "$UserName" -p "$Permissions1" -o "Folder" -s "Native"
        }
    }
}