0
votes

I want to upload these local files from system to the fileserver but if i try to use Get-ChildItem I get this message:

Cannot convert argument "address", with value: "System.Object[]", for "Downl convert the "System.Object[]" value of type "System.Object[]" to type "Syste At C:\Users\Administrator\Desktop\MOVEFILES2.ps1:23 char:1 + $WebClient.DownloadFile($Source, $Dest) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

Here is the working script. I want to modify so that it pulls from that path and not having to specify the file name.

#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
Is there any reason as to why you're calling a webclient? Copy-Item or Move-Item should also work across unc paths? Are the workstation and the fileserver member of the same domain, and does the user underwhich the script will be running permission on both places?Kage
I move throughout different test environments which is why is there is a need to always authenticate. Also why I chose to call a webclient. Is there another way ?Pamineo Richards
Hi, why not simply use Copy-Item ?sodawillow

1 Answers

0
votes

I am unable to test this because of the credential thing, but i think this is a simplified version of what you're trying to achieve.

It should Copy all the items in the Sourcefolder to the Destination, Bassicly it maps a drive and then copies it all and then removes the Drive.

$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"