Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
Debugging Powershell脚本正在停止且未按预期工作_Debugging_Powershell 5.0 - Fatal编程技术网

Debugging Powershell脚本正在停止且未按预期工作

Debugging Powershell脚本正在停止且未按预期工作,debugging,powershell-5.0,Debugging,Powershell 5.0,我已经编写了一个脚本来获取系统变量和几个文件夹的副本,我想为几个文件夹的副本创建一个目录,以防止文件夹的重复,我们需要一个检查条件,因此每次运行脚本时,它都不会创建文件夹。比如说 $nfle=New-Item -ItemType "Directory" -Path "D:\Temp\" -Name "foo" [bool]$checkfle=Test-Path "D:\Temp\foo" -PathType Any if ( $checkfle -eq

我已经编写了一个脚本来获取系统变量和几个文件夹的副本,我想为几个文件夹的副本创建一个目录,以防止文件夹的重复,我们需要一个检查条件,因此每次运行脚本时,它都不会创建文件夹。比如说

     $nfle=New-Item -ItemType "Directory" -Path "D:\Temp\" -Name "foo"
        [bool]$checkfle=Test-Path "D:\Temp\foo" -PathType Any
         if ( $checkfle -eq $True)
    {
      Write-Output "$nfle Exists"
    }
    else
    {
   $bnfle=New-Item -ItemType "Directory" -Path "D:\Temp\" -Name ("boo")
    }
  $cpypste=Copy-Item "D:\Temp\foo" -destination "D:\Temp\boo"
  Write-Host "Succesful Copy of Folders"

因此,当我们运行脚本时,它正在创建文件夹foo,同样当我们运行脚本时,它正在显示foo exists,停止脚本不会进入下一行,甚至不会显示消息。在powershell中是否有方法找出脚本停止的原因,或者我是否应该添加更多信息语句。TIA

我已经尝试了提供的演示,它在我这边运行了多次,因此我无法重新创建问题

如果您想在PowwerShell中调试脚本,可以遵循以下链接:

我不确定,为什么要将复制项的结果存储到一个变量中,因为它是空的


希望有帮助

最好从测试路径开始,看看文件夹是否在那里。容器是一个文件夹/目录。然后检查是否需要写入文件夹

 # This should allow your script to continue of error.
 $ErrorActionPreference = "Continue"

 # check if "C:\Temp\Foo" exist. if not make C:\Temp\foo"

 $nfle = 'C:\Temp\foo'

 [bool]$checkfle = Test-Path $nfle -PathType Container
 if ( $checkfle -eq $True)
    {
        Write-Output "$nfle Exists"
    }
 else
    {
        New-Item -ItemType "Directory" -Path "C:\Temp\" -Name "foo"    
    }

# check if "C:\Temp\boo" exist. if not make C:\Temp\boo"

$BooFilePath = "C:\Temp\boo"

[bool]$checkboo = Test-Path $BooFilePath -PathType Container

 if ( $checkboo -eq $True)
    {
        Write-Output " $BooFilePath Exists"
    }
 else
    {
        New-Item -ItemType "Directory" -Path "C:\Temp\" -Name "boo"    
    }

# This makes the folder C:\Temp\boo\foo.
# $cpypste = Copy-Item -Path "C:\Temp\foo\" -destination "C:\Temp\boo\"

# If you want copy the contents of foo into boo you will need * or -recurse
$cpypste = Copy-Item -Path "C:\Temp\foo\*" -destination "C:\Temp\boo\" -PassThru


Write-Host "Succesful Copy of Folders"
$cpypste.FullName