2016-09-29 39 views
0

移動從本地機文件時,文件服務器我想這些本地文件從系統上傳到文件服務器,但如果我嘗試使用Get-ChildItem我得到這個消息:遇到問題包括所有子項中使用PowerShell

對於 ,無法轉換參數「地址」,值爲:「System.Object []」,Downl將類型爲「System.Object []」 的「System.Object []」值轉換爲鍵入「Syste At C: \ Users \ Administrator \ Desktop \ MOVEFILES2.ps1:23 char:1 + $ WebClient.DownloadFile($ Source,$ Dest) + ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ecified:(:) [],MethodException + FullyQualifiedErrorId:MethodArgumentConversionInvalidCastArgument

這裏是工作的腳本。我想修改它以便從該路徑拉出而不必指定文件名。

#UPLOAD FILES FROM SOURCE TO File server 
# Specify the path to the documents you want to upload from the local machine... 
$Source = "C:\Users\Administrator\Desktop\SourceFolder\Goober.docx" 
$Dest = "\\10.112.4.111\xx\xxxxx\xxxx xxxxx\xxxx\Goober.docx"  
# Specify Username and Password 
$Username = "domain\user" 
$Password = "xxxxxxxxxxx"  
# Generate System.Net.WebClient object 
$WebClient = New-Object System.Net.WebClient 
$WebClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password) 
$WebClient.DownloadFile($Source, $Dest) 
+1

是否有任何理由爲什麼你要調用webclient? Copy-Item或Move-Item也應該在unc路徑上工作?是同一個域的工作站和文件服務器成員,並且腳本將在哪兩個位置上運行權限的用戶? – Kage

+0

我在不同的測試環境中移動,這就是爲什麼總是需要進行身份驗證。另外,我爲什麼選擇致電一個web客戶端。有另一種方法嗎? –

+0

嗨,爲什麼不簡單地使用'Copy-Item'? – sodawillow

回答

0

我無法測試這是因爲憑證的事情,但我認爲這是您試圖實現的簡化版本。

它應該將Sourcefolder中的所有項目複製到目標,Bassicly會映射一個驅動器,然後將其全部複製,然後刪除驅動器。

$sourceFolder = "C:\Users\Administrator\Desktop\SourceFolder" 
$Destination = "\\10.112.4.111\xx\xxxxx\xxxx xxxxx\xxxx" 

$secpw = ConvertTo-SecureString "Password" -AsPlainText -Force 
$creds = New-Object System.Management.Automation.PSCredential("Username",$secpw) 

New-PSDrive -Name "Dest" -PSProvider FileSystem -Root $dest -Credential $creds 
Copy-Item $sourceFolder "Dest:\" -Recurse 
Remove-PSDrive -Name "Dest"