2016-04-27 15 views
-1
gebunden werden

Wie bekomme ich dieses Powershell-Programm zur erfolgreichen Ausführung?Das Argument kann nicht an Parameter

$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

+0

Sie Fehler bekommen Sie es bei der Ausführung? –

+0

New-Item: Das Argument an Parameter 'Path' kann nicht gebunden werden, da es null ist. $ Dest: + CategoryInfo InvalidData (:) [Neu-Item], ParameterBindingValidationException + FullyQualifiedErrorId: ParameterArgumentValidationErrorNullNotAllowed – Peter

+0

Ich habe eine Antwort gepostet, bitte überprüfen Sie es. –

Antwort

1

Sie möchten setzen diese $ Source = "\ ahs-bind01 \ ftptest01 \ CRAR" Get-ChildItem -Path $ Quelle -Recurse jedes seiner Linie wie folgt aus:

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

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

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

Same mit $ 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 

bearbeiten auch ($ .PSIsContainer -eq $ true) -und ($ .FullName -match "$ Source") zu:

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

geändert. Ja, der Code ist bereits so ausgerichtet, wie Sie es vorgeschlagen haben. Wenn ich auf diese Website kopiere und eingefügt habe, wurde alles um – Peter

+0

geändert. Sieht aus wie $ UNC = $ sheet.Cells.Item ($ rowUNC + $ i, $ colUNC) .text $ Path = Get-ChildItem -Pfad $ UNC -recurse | Where-Object {($ .PSIsContainer -eq $ true) -und ($ .FullName -match "$ Source"}} gibt keine Werte zurück, Sie müssen auch Excel-Daten für diese bestimmte Zelle und die $ UNC-Variable überprüfen. –