无法将参数绑定到参数“Path”因为它是空的。参数似乎根本不为空

发布于 2025-01-18 18:55:12 字数 1983 浏览 2 评论 0原文

检查远程计算机上是否存在文件:

 #Check if Dir exists on the machine we are copying from
            $dir = ($APPROD001Root + $instance + "\" + $type + "\" + $year + "\" + $monthFormatted)
            Write-Host $dir
            if(Test-Path -Path $dir){
                Write-Host ($dir + " exists!") 
                $files = Get-ChildItem -Path $dir

                #Check if the Dir has files in it
                if($files.Length -gt 0){
                    #Check if the folder exists on the machine we are copying towards, if not create it!
                    $dirReceivingMachine = ($DBStag01Root + $instance + "\" + $type + "\" + $year + "\" + $monthFormatted)
                    Write-Host $dirReceivingMachine
                    if($dirReceivingMachine -eq $null){
                        Write-Host "the path is null..."
                    }
                    $folderExists = Invoke-Command -ScriptBlock { Test-Path -Path $dirReceivingMachine } -Session $session 
                    if(!$folderExists){
                        Write-Host ("folder " + $dirReceivingMachine + " does not yet exist we want to create it!")
                        #Invoke-Command - ScriptBlock { New-Item -Path $dirReceivingMachine -ItemType Directory } -Session $session
                    }

设置$ folderexists始终投掷的命令命令

无法将参数与参数“路径”结合,因为它为null。 + categoryInfo:InvalidData:{:) [test-Path],parameterBindingValidationException + firmomqualifyErrid:参数argumentValidationErrornullnotlower,Microsoft.powershell.commands.testpathcommand

我在终端中获得的输出IS

d:mydata \ 2018 \ 09 D:\ mydata \ 2018 \ 09存在! D:\ mydata \ 2018 \ 09不能将参数绑定到 参数“路径”,因为它为空。 + categoryInfo:InvalidData:(:) [test-Path],parameterBindingValidationException

As you can see the Write-Host "The path is null.." never fires, so the variable I am passing into Test-Path is not null yet PS says是在调用命令的时候...

不知道为什么要这样做

Checking if a file exists on a remote machine:

 #Check if Dir exists on the machine we are copying from
            $dir = ($APPROD001Root + $instance + "\" + $type + "\" + $year + "\" + $monthFormatted)
            Write-Host $dir
            if(Test-Path -Path $dir){
                Write-Host ($dir + " exists!") 
                $files = Get-ChildItem -Path $dir

                #Check if the Dir has files in it
                if($files.Length -gt 0){
                    #Check if the folder exists on the machine we are copying towards, if not create it!
                    $dirReceivingMachine = ($DBStag01Root + $instance + "\" + $type + "\" + $year + "\" + $monthFormatted)
                    Write-Host $dirReceivingMachine
                    if($dirReceivingMachine -eq $null){
                        Write-Host "the path is null..."
                    }
                    $folderExists = Invoke-Command -ScriptBlock { Test-Path -Path $dirReceivingMachine } -Session $session 
                    if(!$folderExists){
                        Write-Host ("folder " + $dirReceivingMachine + " does not yet exist we want to create it!")
                        #Invoke-Command - ScriptBlock { New-Item -Path $dirReceivingMachine -ItemType Directory } -Session $session
                    }

The invoke-command that sets the $folderExists always throws

Cannot bind argument to parameter 'Path' because it is null.
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand

the output I get in terminal is

D:MyData\2018\09
D:\MyData\2018\09 exists!
D:\MyData\2018\09 Cannot bind argument to
parameter 'Path' because it is null.
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException

As you can see the Write-Host "The path is null.." never fires, so the variable I am passing into Test-Path is not null yet PS says it is when invoking the command...

No idea why it does this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文