[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] 网上下载的PowerShell,改了改path,发现file2 识别不了,请高手指点!谢谢

  1. $file1 = GI C:\TEMP\schlecht\Settings.xml
  2. $file2 = GI C:\TEMP\gut\Settings.xml    #路径是对的,确认了n遍
  3. function Compare-Files{
  4. param(
  5. $file1,$file2,[switch]$IncludeEqual)
  6. $content1 = Get-Content $file1
  7. $content2 = Get-Content $file2
  8. $comparedLines = Compare-Object $content1 $content2 -IncludeEqual:$IncludeEqual |
  9. group { $_.InputObject.ReadCount } # | sort Name
  10. $comparedLines | foreach {
  11. $curr=$_
  12. switch ($_.Group[0].SideIndicator){
  13. “==” { $right=$left = $curr.Group[0].InputObject;break}
  14. “=>” { $right,$left = $curr.Group[0].InputObject,$curr.Group[1].InputObject;break }
  15. “<=" { $right,$left = $curr.Group[1].InputObject,$curr.Group[0].InputObject;break }
  16. }
  17. [PSCustomObject] @{
  18. Line = $_.Name
  19. Left = $left
  20. Right = $right
  21. }
  22. }
  23. }
复制代码
下图是报警

Get-Content : Cannot bind argument to parameter 'Path' because it is null.
At C:\TEMP\PS\test_1.ps1:16 char:26
+  $content2 = Get-Content $file2
+                          ~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-Content], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetContentCommand

Compare-Object : Cannot bind argument to parameter 'DifferenceObject' because it is null.
At C:\TEMP\PS\test_1.ps1:17 char:44
+  $comparedLines = Compare-Object $content1 $content2 -IncludeEqual:$IncludeEqual ...
+                                            ~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Compare-Object], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand

Cannot index into a null array.
At C:\TEMP\PS\test_1.ps1:20 char:2
+  $curr=$_
+  ~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

返回列表