Powershell 的自动部署



工作中重复性的版本移植,一天上线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|?{$_.

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值