two ask for powershell script
Hi,
I want use a Powershell script for download file on few serveur (20-30).
Can i use WinSCPnet.dll whitout $sessionOptions.SshHostKeyFingerprint ?
And can i read on a file HostName and password ... ?
I have test a many solution with Get-Content and Foreach-Object.
and now i have no idea for creating this script
Thanks so much
King Regards
Jhon
My script:
try
{
[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null
ForEach ($liste_srv in Get-Content "z:\projet_enable\liste_serveur.txt")
($liste_mdp in Get-Content "z:\projet_enable\liste_mdp.txt")
($liste_ssh in Get-Content "z:\projet_enable\liste_ssh.txt")
}
{
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = $liste_srv
$sessionOptions.UserName = "root"
$sessionOptions.Password = $liste_mdp
$sessionOptions.SshHostKeyFingerprint = $liste_ssh
$session = New-Object WinSCP.Session
try
{
$session.Open($sessionOptions)
$session.GetFiles("/home/gconf/*.gz", "C:\Users\adm-l2b-jherve\test\*").check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}
ForEach ($system in Get-Content "liste_serveur.txt")
{
Write-Host $system
Write-Host " "
}
exit 1
I want use a Powershell script for download file on few serveur (20-30).
Can i use WinSCPnet.dll whitout $sessionOptions.SshHostKeyFingerprint ?
And can i read on a file HostName and password ... ?
I have test a many solution with Get-Content and Foreach-Object.
and now i have no idea for creating this script
Thanks so much
King Regards
Jhon
My script:
try
{
[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null
ForEach ($liste_srv in Get-Content "z:\projet_enable\liste_serveur.txt")
($liste_mdp in Get-Content "z:\projet_enable\liste_mdp.txt")
($liste_ssh in Get-Content "z:\projet_enable\liste_ssh.txt")
}
{
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = $liste_srv
$sessionOptions.UserName = "root"
$sessionOptions.Password = $liste_mdp
$sessionOptions.SshHostKeyFingerprint = $liste_ssh
$session = New-Object WinSCP.Session
try
{
$session.Open($sessionOptions)
$session.GetFiles("/home/gconf/*.gz", "C:\Users\adm-l2b-jherve\test\*").check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}
ForEach ($system in Get-Content "liste_serveur.txt")
{
Write-Host $system
Write-Host " "
}
exit 1