我想将这些本地文件从系统上传到文件服务器,但如果我尝试使用Get-ChildItem,我会收到以下消息:
无法转换参数“address”,其值为:“System.Object []”,for “下载转换”System.Object []“类型”System.Object []“的值 键入“Syste At C:\ Users \ Administrator \ Desktop \ MOVEFILES2.ps1:23 焦炭:1 + $ WebClient.DownloadFile($ Source,$ Dest) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [],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)
答案 0 :(得分:0)
由于凭证的原因,我无法对此进行测试,但我认为这是您尝试实现的简化版本。
它应该将Sourcefolder中的所有项目复制到Destination,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"