Powershell 的自动部署

本文介绍了一种使用Powershell自动化部署应用程序到Linux服务器的方法,涉及Wincp、powershell的ssh-session模块和.NET。通过编写脚本,实现从Windows环境到Linux的程序部署和文件上传,包括连接、执行shell命令、解密密码、创建备份及移植操作。
摘要由CSDN通过智能技术生成


工作中重复性的版本移植,一天上线10几次,让我痛不欲生,频繁的操作也可能出现疲劳性失误,导致严重的生产故障。于是乎,闲暇时间,我开始研究使用powershell自动部署程序到Linux服务器。

脚本中涉及到以下工具:

1、Wincp:借助其自身的命令行模式完成程序部署

2、powershell的ssh-session模块,通过加载该模块连接到Linux服务器,执行相关shell命令

3、.net


开始上代码


#Public environment configure
$script:linuxPath="D:\test\newpath.txt"
$script:parentPath="D:\test\"
$script:parentPath2=$parentPath -replace ""
$script:projectConfigureFile="D:\test\projectConfigureFile.csv"


#执行shell函数
function Exec-Bash($computers,$user,$pwd,$linux_command){
    #Check SshSessions Module
    $modules=Get-Command -Module ssh-sessions
    if($modules -eq $null){
        Import-Module ssh-sessions
    }
    if($computers.GetType().IsArray){
        foreach($computer in $computers){
            $sshsession=Get-SshSession|?{$_.computername -eq $computer}
            if($sshsession.Connected -ne "true"){
                New-SshSession -ComputerName $computer -Username $user -Password $pwd -ErrorAction Stop
            }
            Invoke-SshCommand -ComputerName $computer -Quiet -Command $Linux_command
        }
    }else{
        $sshsession=Get-SshSession|?{$_.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值