Sorry, I don't think you can. Copy-Item doesn't support the -credential parameter,
"This parameter appears,
but it is not supported in any Windows PowerShell core cmdlets or providers"
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
> Thanks Shay - is there anyway of doing this with copy-item - to
> securely code the credentials into this command
> "Shay Levi" wrote:
>> Check the help for Copy-Item:
>> -credential <PSCredential>
>> Specifies a user account that has permission to perform this action.
>> Type a user-name, such as "User01" or "Dom
>> ain01\User01", or enter a PSCredential object, such as one from the
>> Get-Credential cmdlet. If you type a user n
>> ame, you will be prompted for a password. This parameter appears,
>> but it is not supported in any Windows PowerS
>> hell core cmdlets or providers.
>> You can see the error if you try to run a copy-item command with
>> PS > copy-item c:\boot.ini d:\temp -Credential userName # you are
>> prompted for password, type a password and press enter
>> Copy-Item : Cannot retrieve the dynamic parameters for the cmdlet.
>> to perform the MakePath operation operati
>> on on the 'FileSystem' provider failed for path ''. The provider does
>> support the use of credentials. Please perfor
>> m the operation again without specifying credentials.
>> At line:1 char:10
>> + copy-item <<<< c:\boot.ini d:\temp -Credential username
>> Shay Levi
>> $cript Fanatic
>> Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
>>> I have tried to implement the following piece of code with no
>>> success - I also can find nothing on this on the web - could someone
>>> perhaps point me in the right direction - I had previously saved the
>>> password to disk (as per Lee Holmes book)
>>> #ping and copy to a server (10.xx.xx.xx) if directory still exists
>>> $strComputerF = "10.xx.xx.xx"
>>> $password = Get-Content c:\temp\password.txt |
>>> $credential = New-Object System.Management.Automation.PSCredential
>>> $ping = new-object System.Net.NetworkInformation.Ping
>>> $Reply = $ping.send($strComputerF)
>>> if(($Reply.status -eq "success") -and (Test-Path
>>> Copy-Item $CSVFilePath \\$strComputerF\Share$\Test -Credential