#  ,       Set-ExecutionPolicy remotesigned -scope currentuser #     ssh Install-Module -Name Posh-SSH Import-Module posh-ssh $curDir = $MyInvocation.MyCommand.Definition | split-path -parent function bkprtr { param($ipaddr) #          ftp  ssh. $secpasswd = ConvertTo-SecureString "___" -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ("___", $secpasswd) $error.clear() #  ssh      New-SSHSession -ComputerName $ipaddr -Credential $mycreds -Force Invoke-SshCommand -index 0 -Command "system backup save name temp.backup" Get-SSHSession | Remove-SshSession; $Cdate=get-date -Uformat %Y%m%d $rptpath = "$curDir\backup\$cdate" #    if (!(test-path -path $rptpath)) {new-item -path $rptpath -itemtype directory} #  wget -Uri "ftp://$ipaddr/temp.backup" -OutFile "$rptpath\$ipaddr.backup" -Credential $mycreds #     If ($error.count -gt 0) { get-date | out-file "$curDir\error.log" -append $ipaddr | out-file "$curDir\error.log" -append $error | out-file "$curDir\error.log" -append $error.clear() } } #  list.txt  foreach ($ip in gc $curDir\list.txt ){bkprtr($ip)}  #  ,       Set-ExecutionPolicy remotesigned -scope currentuser #     ssh Install-Module -Name Posh-SSH Import-Module posh-ssh $curDir = $MyInvocation.MyCommand.Definition | split-path -parent function bkprtr { param($ipaddr) #          ftp  ssh. $secpasswd = ConvertTo-SecureString "___" -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ("___+ct", $secpasswd) $error.clear() $Cdate=get-date -Uformat %Y%m%d $rptpath = "$curDir\backup\$cdate" #    if (!(test-path -path $rptpath)) {new-item -path $rptpath -itemtype directory} #  #  ssh      $sshsession=New-SSHSession -ComputerName $ipaddr -Credential $mycreds -Force $ssh = $sshSession | New-SSHShellStream start-sleep -s 5 $ssh.read() | out-null $ssh.WriteLine( "export" ) start-sleep -s 15 $ssh.read() | sc "$rptpath\$ipaddr.backup" $tfileproc=gc "$rptpath\$ipaddr.backup" $tfileproc[2..($tfileproc.count-2)]|sc "$rptpath\$ipaddr.backup" Get-SSHSession | Remove-SshSession; #     If ($error.count -gt 0) { get-date | out-file "$curDir\error.log" -append $ipaddr | out-file "$curDir\error.log" -append $error | out-file "$curDir\error.log" -append $error.clear() } } Source: https://habr.com/ru/post/351108/
All Articles