Powershell 无法将参数绑定到参数

Powershell 无法将参数绑定到参数,powershell,powershell-2.0,Powershell,Powershell 2.0,如何使此powershell程序成功执行 $Source = "\\ahs-bind01\ftptest01\CRAR" Get-ChildItem -Path $Source -recurse #Declare the file path and sheet name $file = "C:\Users\us6205\Desktop\DatabaseNameConfigs\Test\CareMoveFileParentDestPaths.xlsx" $sheetName = "shee

如何使此powershell程序成功执行

$Source = "\\ahs-bind01\ftptest01\CRAR"
Get-ChildItem -Path $Source -recurse

 #Declare the file path and sheet name

$file = "C:\Users\us6205\Desktop\DatabaseNameConfigs\Test\CareMoveFileParentDestPaths.xlsx"

$sheetName = "sheet1" 


 #Create an instance of Excel.Application and Open Excel file

$objExcel = New-Object -ComObject Excel.Application

$workbook = $objExcel.Workbooks.Open($file) 

$sheet = $workbook.Worksheets.Item($sheetName)

$objExcel.Visible=$false 


 #Count max row

$rowMax = ($sheet.UsedRange.Rows).count 

 #Declare the starting positions

$rowLOC,$colLOC = 1,1
$rowUNC,$colUNC = 1,2 


 #loop to get values and store it 

for ($i=1; $i -le $rowMax-1; $i++)

{ 

$LOC = $sheet.Cells.Item($rowLOC+$i,$colLOC).text
$UNC = $sheet.Cells.Item($rowUNC+$i,$colUNC).text 

$Path = Get-ChildItem -Path $UNC -recurse |
 Where-Object { ($_.PSIsContainer -eq $true) -and  ( $_.FullName -match "$Source") } 
 $Dest = $Path | New-Item -path $Dest -itemtype directory | Move-Item -Path $Source -Destination $Dest -Force
 }

 #close excel file

$objExcel.quit() 

您希望将这些$Source=“\ahs-bind01\ftptest01\CRAR”Get ChildItem-Path$Source-recurse分别放在其行中,如下所示:

$Source = "\ahs-bind01\ftptest01\CRAR" 
Get-ChildItem -Path $Source -recurse
$rowLOC、$colLOC=1,1$rownc、$colUNC=1,2相同

$rowLOC,$colLOC = 1,1
$rowUNC,$colUNC = 1,2
$LOC=$sheet.Cells.Item($rowLOC+$i,$colLOC)相同。text$UNC=$sheet.Cells.Item($rownc+$i,$colUNC)。text

$LOC = $sheet.Cells.Item($rowLOC+$i,$colLOC).text 
$UNC = $sheet.Cells.Item($rowUNC+$i,$colUNC).text
还可以编辑($.PSIsContainer-eq$true)和($.FullName-match“$Source”)

($_.PSIsContainer -eq $true) -and ( $_.FullName -match "$Source")

执行时是否出现任何错误?新项:无法将参数绑定到参数“Path”,因为它为null$Dest:+CategoryInfo InvalidData(:)[New Item],ParameterBindingValidationException+FullyQualifiedErrorId:ParameterArgumentValidationErrorNullNotAllowed我已经发布了答案,请检查。是的,代码已经按照您的建议排列好了。当我复制并粘贴到这个网站时,周围的一切都发生了变化是的,代码已经按照你的建议排列好了。当我复制并粘贴到此网站时,周围的一切都发生了更改,看起来像$UNC=$sheet.Cells.Item($rownc+$I,$colUNC)。text$Path=Get-ChildItem-Path$UNC-recurse |其中Object{($.PSIsContainer-eq$true)-和($.FullName-match“$Source”)}不返回任何值,您必须检查该特定单元格上的excel数据以及$UNC变量。