如何让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()
答案 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")