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神秘错误_Powershell - Fatal编程技术网

Powershell神秘错误

Powershell神秘错误,powershell,Powershell,请帮忙!我不知道该怎么办。 脚本按内容拆分文件: $InPC = "C:\Scripts\" Get-ChildItem $InPC -Filter *.prt | ForEach-Object -Process { $basename= $_.BaseName $m = ( ( Get-Content $_ | Where { $_ | Select-String "--------------------- Instance Type and Tr

请帮忙!我不知道该怎么办。 脚本按内容拆分文件:

$InPC = "C:\Scripts\"

Get-ChildItem $InPC -Filter *.prt | ForEach-Object -Process { 
        $basename= $_.BaseName   
        $m = ( ( Get-Content $_ | Where { $_ | Select-String "---------------------  Instance Type and Transmission --------------" -Quiet } | Measure-Object | ForEach-Object { $_.Count } ) -ge 2) 
        $a=1
        if ($m) {
  Get-Content $_ | % {

    If ($_ -match "---------------------  Instance Type and Transmission --------------") {
        $OutputFile = "$basename-$a.prt"
        $a++
    }    
    Add-Content $OutputFile $_
    }
  Remove-Item $_ 
  }
  }
当我将location设置为C:\Scripts时,一切都正常。但在基本情况下,它将不起作用,并给出下一个错误:

Get-Content : Path not found "C:\Users\a.ulianov\PRTPRT.prt".
C:\Scripts\2.ps1:23 знак:18
+         $m = ( ( Get-Content $_ | Where { $_ | Select-String "------------------ ...
+                  ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\a.ulianov\PRTPRT.prt:String) [Get-Content], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Get-Content : Path not found "C:\Users\a.ulianov\test.prt".
C:\Scripts\2.ps1:23 знак:18
+         $m = ( ( Get-Content $_ | Where { $_ | Select-String "------------------ ...
+                  ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\a.ulianov\test.prt:String) [Get-Content], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
它似乎在执行过程中使用默认的PS位置。在这种情况下,我可以修改什么

# 多亏了@Raf@Rynant,这里有一个小小的弯曲但有效的解决方案:

$InPC = "C:\Scripts"
Get-ChildItem -Path $InPC -Filter *.prt | ForEach-Object -Process { 
        $basename= $_.BaseName   
        $m = ( ( Get-Content $_.FullName | Where { $_ | Select-String "---------------------  Instance Type and Transmission --------------" -Quiet } | Measure-Object | ForEach-Object { $_.Count } ) -ge 2) 
        $a = 1
        if ($m) {
  Get-Content $_.FullName | % {

    If ($_ -match "---------------------  Instance Type and Transmission --------------") {
        $OutputFile = "$InPC\$basename _$a.prt"
        $a++
    }    
    Add-Content $OutputFile $_
    }
  Remove-Item $_.FullName 
  }
  } 

看起来有点凌乱,但我认为您需要做的唯一更改是更换:

获取内容$\u

Get Content$\ux.FullName

这不是一个真正的问题,但是
$basename=%{$\uuu.basename}
应该是
$basename=$\uuu.basename
谢谢,我更正了脚本这并没有起作用(((此时的结果是在
C:\Windows\system32
创建了较新的拆分文件,并且
删除项目
也需要
$。
。我不知道PS ISE到底是怎么回事,但启动时会随机选择默认位置,例如
C:\Users\a.ulianov
C:\Program files\Microsoft Office\Office14
等等。一个问题是,为什么它不能处理它们所在位置的文件?我修改了脚本,它看起来可能有点歪,但它可以工作。