Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
powershell变量目录返回null_Powershell - Fatal编程技术网

powershell变量目录返回null

powershell变量目录返回null,powershell,Powershell,我正在尝试获取一个文件列表,这些文件不是我想要的版本,我创建了一个包含3个变量的函数: 版本号 文件夹的名称 文件夹的路径 如果文件版本与$version不匹配,我会将行写出来,以便知道文件名和实际版本号 Function Check-Version ($version, $folderName, $folderPath) { Write-Host $version, $folderName, $folderPath $list = get-childitem $folder

我正在尝试获取一个文件列表,这些文件不是我想要的版本,我创建了一个包含3个变量的函数:

  • 版本号
  • 文件夹的名称
  • 文件夹的路径
如果文件版本与
$version
不匹配,我会将行写出来,以便知道文件名和实际版本号

Function Check-Version ($version, $folderName, $folderPath)
{
    Write-Host $version, $folderName, $folderPath
    $list = get-childitem $folderPath\* -include *.dll,*.exe
    foreach ($one in $list)
    {
        If ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($one).FileVersion -ne $version)
        {
            $line = "{0}`t{1}" -f [System.Diagnostics.FileVersionInfo]::GetVersionInfo($one).FileVersion, $one.Name
            Write-Host $line
        }
    }
}

Check-Version ("1.0", "bin", "C:\bin")
我的问题是,当我使用
get childitem
时,path变量为NULL,但如果我使用
write host
则是正确的

顶部的
Write Host
行返回正确的值

如果我尝试
cd$folderPath
我会得到错误:

cd:无法处理参数,因为参数“path”的值为null。将参数“path”的值更改为非空值


我不明白为什么当我尝试转到该目录时,
$folderPath
为空。

您的问题是将3个参数作为数组传递到第一个参数,而不是传递三个单独的参数。更改
检查版本(“1.0”,“bin”,“C:\bin”)
->
检查版本“1.0”“bin”“C:\bin”

通过将
写入主机
拆分为3行,您可以看到差异:

Function Check-Version ($version, $folderName, $folderPath) {
    Write-Host "Version: $version"
    Write-Host "FolderName: $folderName"
    Write-Host "FolderPath: $folderPath"
    $list = get-childitem $folderPath\* -include *.dll,*.exe
    Set-Location $folderPath
    foreach ($one in $list) {
        If ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($one).FileVersion -ne $version) {
            $line = "{0}`t{1}" -f [System.Diagnostics.FileVersionInfo]::GetVersionInfo($one).FileVersion, $one.Name
            Write-Host $line
        }
    }
}

Check-Version "1.0" "bin" "C:\bin"

谢谢我应该看到的。