脚本的哪一部分正在打印目录信息?

What part of the script is printing the directory information?

我在从 SQL 表中读取并将结果附加到列出的变量的 PowerShell 脚本 (Process.ps1) 中有以下内容:

function Query($Query) {
    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection 
    $SqlConnection.ConnectionString = "Server=$Server;Initial Catalog=$Database;Integrated Security=SSPI" 
    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand 
    $SqlCmd.Connection = $SqlConnection 
    $SqlCmd.CommandText = $Query 
    $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter 
    $SqlAdapter.SelectCommand = $SqlCmd 
    $DataSet = New-Object System.Data.DataSet 
    $a=$SqlAdapter.Fill($DataSet)
    $SqlConnection.Close() 
    $DataSet.Tables[0]
}

$Result = Query "SELECT * from [$cubeTable]" | Out-GridView -Wait;

$CUBE = Query "SELECT [cube_name] FROM [$cubeTable] WHERE [cube_name] = '$CUBE_input'" | Select -ExpandProperty cube_name;

$Destination_Server = Query "SELECT [destination_server] FROM [$cubeTable] WHERE [cube_name] = '$CUBE'" | Select -ExpandProperty destination_server;

$BasePath = Query "SELECT [variable_value] FROM [$pathTable] WHERE [variable_name] = 'base_path'" | Select -ExpandProperty variable_value;

$jsonPath = Join-Path -Path $BasePath -ChildPath $jsonDirectory
New-Item -ItemType Directory -Force -Path $jsonPath

$JSON_file = Join-Path $jsonPath $CUBE |
             %{ ($_ + ".json") }

$processPATH = Join-Path -Path $BasePath -ChildPath $process_output_Directory
New-Item -ItemType Directory -Force -Path $processPATH

$process_output = Join-Path $processPATH $CUBE |
                  %{ ($_ + ".txt") }

$autosysPATH = Join-Path -Path $BasePath -ChildPath $AUTOSYS_output_Directory
New-Item -ItemType Directory -Force -Path $autosysPATH

$process_AUTOSYS_output = Join-Path $autosysPATH $CUBE |
                          %{ ($_ + "_process.txt") }

当我 运行 通过批处理文件在 CMD 中运行脚本时,它 运行 非常好,但是,它从以下变量的某个地方输出这些目录信息:

json_file, process_output, and autosys_output

我这里有一个输出图像:

写入控制台的确切位置在哪里?我没有任何回声或 Write-Host!更不用说输出目录的函数了...

绝对不是这一部分:$Result = Query "SELECT * from [$cubeTable]" | Out-GridView -Wait; 因为我将其注释掉了,它仍然输出目录信息,如屏幕截图所示。

New-Item returns 创建的 FileInfoDirectoryInfo 对象。这就是您在输出中看到的内容。 PowerShell 默认输出格式只是合并相似的连续对象以提供更紧凑的输出,因此您得到一个 table 而不是三个单独的 table,每个对象一个对象。

您可以通过将 | Out-Null 添加到 New-Item 语句来抑制输出:

New-Item -ItemType Directory -Force -Path $jsonPath | Out-Null

其他选项是在变量中捕获输出或使用重定向 (> $null)。