无法将参数绑定到参数

时间:2016-04-27 15:02:30

标签: powershell powershell-v2.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 = "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() 

screenshot

1 个答案:

答案 0 :(得分:1)

你想把这些 $ Source =“\ ahs-bind01 \ ftptest01 \ CRAR”Get-ChildItem -Path $ Source -recurse 分别放到这一行:

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

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

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

$ LOC = $ sheet.Cells.Item($ rowLOC + $ i,$ colLOC)相同.text $ UNC = $ sheet.Cells.Item($ rowUNC + $ 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")