locked
Credential on the background RRS feed

  • Question

  • I'm trying to push file to multiple servers. I was able to collect information from internet.

    [code]

    Read-Host "Er Password" -AsSecureString | ConvertFrom-SecureString | Out-File PSCred.txt
    $Pass = cat PSCred.txt | ConvertTo-SecureString
    $User = Read-Host "ER userID"
    $computers = gc "C:\temp\servers.txt"
    $source = "C:\temp\UPowercli.exe"
    $destination = "C$\temp\"
    foreach ($computer in $computers) {Copy-Item $source -Credential $User $Pass -Destination "\\$computer\$destination" -Recurse}

    [/code]

    I get pop up asking for credential even when I added <-Credential $User $Pass>

    What am I missing?

    What does this mean?

    The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform the operation again without specifying credentials.

    + ... computers) {Copy-Item $source -Credential $User $Pass -Destination "\ ...

    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotImplemented: (:) [], PSNotSupportedException

        + FullyQualifiedErrorId : NotSupported

    Copy-Item : A positional parameter cannot be found that accepts argument 'System.Security.SecureString'.

    + ... computers) {Copy-Item $source -Credential $User $Pass -Destination "\ ...

    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidArgument: (:) [Copy-Item], ParameterBindingException

        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.CopyItemCommand


    • Edited by NautTboy Thursday, October 3, 2019 5:00 PM remove confidential
    Thursday, October 3, 2019 4:59 PM

All replies

  • The error message tells you exactly what is wrong. Did you read it? You highlighted the line.  It is explicit.  You cannot do what you are trying to do.


    \_(ツ)_/

    Thursday, October 3, 2019 5:04 PM
  • Use Start-Job with the credentials and the copy will work.

    help start-job -online


    \_(ツ)_/

    Thursday, October 3, 2019 5:06 PM
  • Thanks for giving me the right direction.

    here's what I have now:
    Read-Host "Er Password" -AsSecureString | ConvertFrom-SecureString | Out-File c:\temp\PSCred.txt
    $Pass = cat PSCred.txt | ConvertTo-SecureString
    $User = Read-Host "ER userID"
    $computers = gc "C:\temp\servers.txt"
    $source = "C:\temp\UPowercli.exe"
    $destination = "C$\temp\"
    foreach ($computer in $computers)

    {
    $copy = [scriptblock]::create("Copy-Item $source -Destination \\$computer\$destination -Recurse")
    start-job -scriptblock -Credential $User $Pass $copy
    }

    I'm getting

    Missing an argument for parameter 'ScriptBlock'. Specify a parameter of type 'System.Management.Automation.ScriptBlock' and try again

    is my { } on the wrong spot?

     

    Friday, October 4, 2019 12:55 PM
  • Before wasting your time guessing at everything you need to read the complete help carefully and take some time to learn PowerShell.

    This is an example of how to use PS to create a job with a scriptblock.

    $cred = Get-Credential $user
    $sb = {
    	param($computer)
    	Copy-Item C:\temp\UPowercli.exe -Destination  "\\$computer\C$\temp"
    }
    
    Get-Content C:\temp\servers.txt |
    ForEach-Object{ Start-Job -scriptblock $sb -Credential $cred -ArgumentList $computer }


    \_(ツ)_/

    Friday, October 4, 2019 2:21 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Tuesday, October 8, 2019 8:35 AM