标题: [问题求助] 网上下载的PowerShell,改了改path,发现file2 识别不了,请高手指点!谢谢 [打印本页]
作者: PS_2015 时间: 2015-1-16 13:39 标题: 网上下载的PowerShell,改了改path,发现file2 识别不了,请高手指点!谢谢
- $file1 = GI C:\TEMP\schlecht\Settings.xml
- $file2 = GI C:\TEMP\gut\Settings.xml #路径是对的,确认了n遍
- function Compare-Files{
- param(
- $file1,$file2,[switch]$IncludeEqual)
- $content1 = Get-Content $file1
- $content2 = Get-Content $file2
- $comparedLines = Compare-Object $content1 $content2 -IncludeEqual:$IncludeEqual |
- group { $_.InputObject.ReadCount } # | sort Name
- $comparedLines | foreach {
- $curr=$_
- switch ($_.Group[0].SideIndicator){
- “==” { $right=$left = $curr.Group[0].InputObject;break}
- “=>” { $right,$left = $curr.Group[0].InputObject,$curr.Group[1].InputObject;break }
- “<=" { $right,$left = $curr.Group[1].InputObject,$curr.Group[0].InputObject;break }
- }
- [PSCustomObject] @{
- Line = $_.Name
- Left = $left
- Right = $right
- }
- }
- }
复制代码
下图是报警
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
作者: yiwuyun 时间: 2015-3-27 10:53
- # 2>nul&@cls&@echo off&powershell -command "&{set-executionPolicy remoteSigned}"© "%~f0" "%~f0.ps1">nul&powershell -file "%~f0.ps1"&del "%~f0.ps1"&pause&exit /b 0
- $file1 = GI C:\TEMP\schlecht\Settings.xml;
- $file2 = GI C:\TEMP\gut\Settings.xml;
- function Compare-Files{
- param(
- $file1,
- $file2,
- [switch]$IncludeEqual
- )
- $content1 = Get-Content $file1;
- $content2 = Get-Content $file2;
- $comparedLines = Compare-Object $content1 $content2 -IncludeEqual:$IncludeEqual | group { $_.InputObject.ReadCount } | sort Name;
- $comparedLines | foreach {
- $curr=$_
- switch ($_.Group[0].SideIndicator){
- "==" { $right=$left = $curr.Group[0].InputObject;break}
- "=>" { $right,$left = $curr.Group[0].InputObject,$curr.Group[1].InputObject;break }
- "<=" { $right,$left = $curr.Group[1].InputObject,$curr.Group[0].InputObject;break }
- }
- [PSCustomObject] @{
- Line = $_.Name;
- Left = $left;
- Right = $right;
- }
- }
- }
- Compare-Files -file1 $file1 -file2 $file2 -IncludeEqual;
复制代码
bat 和powershell均通过。程序是对的,是不是你的策略设置有问题。
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |