Windows Vista Forums

Re: copy-item + passing credentials
  1. #1


    Shay Levi Guest

    Re: copy-item + passing credentials

    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


      My System SpecsSystem Spec

  2. #2


    Hal Rottenberg Guest

    Re: copy-item + passing credentials

    Shay Levi wrote:

    > 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"
    But you can supply credentials when mapping a network drive. He could
    use code similar to this:

    $cred = get-credential "user"
    $user = $cred.UserName
    $net = New-Object -com WScript.Network
    $pwd = $cred.Password
    $drive = "F:"
    $path = "\\server\share";
    if (test-path $drive) { $net.RemoveNetworkDrive($drive) }
    $net.mapnetworkdrive($drive, $path, $true, $user, $pwd)


    --
    Hal Rottenberg <hal@xxxxxx>
    Author, TechProsaic (http://halr9000.com)
    Webmaster, Psi (http://psi-im.org)
    Co-host, PowerScripting Podcast (http://powerscripting.net)

      My System SpecsSystem Spec

Re: copy-item + passing credentials problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with remote file access and passing credentials in Powershell Pete Zerger (MVP) PowerShell 1 10 May 2009
Copy-Item : Container cannot be copied onto existing leaf item. Steve PowerShell 3 17 Mar 2009
programmatically passing network credentials during file IO alan.limebeer .NET General 0 19 Sep 2008
Disable passing RDP inital credentials Brett S Vista networking & sharing 4 15 Nov 2007
Invoke-Item and passing command line parameters =?Utf-8?B?cm9ib3Q=?= PowerShell 5 17 Jul 2006