Posh-SSH
Posh-SSH copied to clipboard
Get-SCPItem doesn't fuse a fully qualified PSCredential
Attempting to automate a SCP from a list of 100 servers and I have to put in the password for every one. Need to be able to use: $credentials = Get-Credential Get-SCPItem -Credential $credentials
looking at NewSessionBase.cs line 198, only Credential.UserName is used
Can the code be updated to detect the presence of a password in the PSCredential object and use that password for authentication?
it works just as you are specifying. Are you sure you dont have an error in your code
PS C:\Users\Carlos Perez> $creds = Get-Credential pi
PS C:\Users\Carlos Perez> Get-SCPItem -Destination ./ -Path /home/pi/klipper/Makefile -Credential $creds -PathType File -ComputerName v0.local -Force -Verbose
VERBOSE: Using SSH Username and Password authentication for connection.
WARNING: Host key is not being verified since Force switch is used.
VERBOSE: Connection successful
VERBOSE: Downloading /home/pi/klipper/Makefile
VERBOSE: File name Makefile
VERBOSE: Item type selected: File
VERBOSE: Saving as C:\Users\Carlos Perez\Makefile
WARNING: Overwritting C:\Users\Carlos Perez\Makefile
here are the bare bones of the script. At every iteration of the for each loop, the credentials widget opens up requesting credentials
class SourceDest {
[string]$Server
[string]$Destination
SourceDest( [string]$s, [string]$d) {
$this.Server = $s
$this.Destination = $d
}
}
$creds = Get-Credential
$list = [SourceDest]::new("servername1", "localfolder1"), [SourceDest]::new("servername2", "localFolder2") # ... (serverN, localhodlerN)
ForEach($item in $list) {
Get-SCPItem -ComputerName $item.Server -Credentials $creds -PathType File -Path "some remote path" -Destination $item.Destination
}
I would recommend setting a breakpoint on the command inside the foreach loop and see if the $cred variable is not populated. Only thing I can think of is that it is in a process block and not a begin block of a a script and pipeline is being used. But best way to check is to debug with a breakpoint