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"
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
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
>> -credential:
>>
>> 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.
>> Attempting
>> to perform the MakePath operation operati
>> on on the 'FileSystem' provider failed for path ''. The provider does
>> not
>> 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
>> http://scriptolog.blogspot.com
>> 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 |
>>> ConvertTo-SecureString
>>> $credential = New-Object System.Management.Automation.PSCredential
>>> "CachedUser",$password
>>> $ping = new-object System.Net.NetworkInformation.Ping
>>> $Reply = $ping.send($strComputerF)
>>> if(($Reply.status -eq "success") -and (Test-Path
>>> \\$strComputerF\Share$\Test)){
>>> Copy-Item $CSVFilePath \\$strComputerF\Share$\Test -Credential
>>> $credential
>>> }else{
>>> cls
>>> }
>>> cls


