这个东东,花了两天来查找资料和测试,终于算是搞定。作记录:

直接在MASTER上执行的命令:

salt '*' cmd.script salt://scripts/windows_task.ps1 args=' -Input c:\tmp\infile.txt' shell='powershell'

直接通过SALT-API执行的命令:

curl -k https://127.0.0.1:8000/ -H "Accept: application/x-yaml" -H "X-Auth-Token: 0ef19709d068834637758b1b5a9af6927a7a651d" -d client='local' -d tgt='cnsz121685-10.25.174.81' -d fun='cmd.script' -d arg='salt://tengine_root/autodeploy/opscripts/test/sbp.ps1' -d arg="static ADE 20160127091855DB backup" -d arg='shell=powershell'

通过我们的API传参考:

if server_sys == 'LINUX':
            args = [salt_cmd.strip(), server_type+' '+site_name+' '+app+' '+deploy_version+' '+action, 'runas='+op_name]
        if server_sys == 'WINDOWS':
            args = [salt_cmd.strip(), server_type+' '+site_name+' '+app+' '+deploy_version+' '+action, 'shell=powershell']
        result = saltapi_inst(server_env).cmd_script(tgt, args)

而自制API用了REQUESTS。

def cmd_script(self, tgt, arg, expr_form='compound', fun='cmd.script'):
        r = requests.post(self.host, verify=False, cookies=self.cookies, data={'tgt': tgt,
                                                                               'client': 'local',
                                                                               'expr_form': expr_form,
                                                                               'fun': fun,
                                                                               'arg': arg})
        if r.status_code == 200:
            # print r.json()
            return r.json()
        else:
            raise Exception('Error from source %s' % r.text)

saltstack远程操作WINDOWS的POWERSHELL脚本的更多相关文章

  1. SaltStack远程执行Windows job程序(黑窗口)填坑经过

    近期接到领导通知,要将公司内的所有Windows服务添加到自动发布系统中,由于这种服务很多,节点分布散乱,每次都是由开发主管手动替换(虽然他们自己开发了自动打包替换工具,但仍需要一台一台登陆到服务器上 ...

  2. 【转】PowerShell入门(六):远程操作

    转至:http://www.cnblogs.com/ceachy/archive/2013/02/20/PowerShell_Remoting.html PowerShell远程操作是远程管理的基础, ...

  3. Windows 上的 SSH?使用 PowerShell Remoting 远程管理 Windows 服务器

    作者:陈计节 个人博客:https://blog.jijiechen.com/post/powershell-remoting/ 在 Linux/Unix 世界里 SSH 是个好东西,SSH 是 Se ...

  4. powershell脚本之windows服务与进程

    powershell脚本之windows服务与进程 服务与进程的区别: Windows服务是指系统自动完成的,不需要和用户交互的过程,可长时间运行的可执行应用程序 进程是程序运行的实例,系统会给运行中 ...

  5. 使用Windows Azure PowerShell远程管理Windows Azure虚拟机

    对于Windows Azure,如果你还在使用windowsazure.com门户来管理虚拟机,那就显得不怎么高上大了.Windows Azure PowerShell 是一个功能强大的脚本环境,可用 ...

  6. 使用Windows任务计划程序运行Windows PowerShell脚本

    创建计划任务以运行PowerShell脚本 我需要创建一个计划任务来运行Windows PowerShell脚本的第一件事是我将执行的命令行.找到这个的简单方法是使用Run 命令.有时,我需要知道什么 ...

  7. 【黑客基础】Windows PowerShell 脚本学习(上)

    视频地址:[黑客基础]Windows PowerShell 脚本学习 2019.12.05 学习笔记 1.$PSVersionTable :查看PowerShell的版本信息. 2.PowerShel ...

  8. 如何在windows计划中调用备份sharepoint2010网站集的powershell脚本

    最近有个项目需要在在windows计划中使用powershell脚本备份sharepoint2010网站集,打开sharepoint的powershell执行命令管理界面的属性 查看: C:\Wind ...

  9. loadrunner 脚本开发-调用java jar文件远程操作Oracle数据库测试

    调用java jar文件远程操作Oracle数据库测试 by:授客 QQ:1033553122 测试环境 数据库:linux 下Oracle_11g_R2 Loadrunner:11 备注:想学ora ...

随机推荐

  1. Android手机一键Root原理分析

    图/文 非虫 一直以来,刷机与Root是Android手机爱好者最热衷的事情.即使国行手机的用户也不惜冒着失去保修的风险对Root手机乐此不疲.就在前天晚上,一年一度的Google I/O大会拉开了帷 ...

  2. JavaScript高级程序开发3笔记

      Js对象 注意:js基本数据类型不是对象,但是"abc".match()这种,可以调用对象的方法,是因为调用方法是临时产生了一个wrapper的包装对象,this指向它: Js ...

  3. CSS 初体验之Line-height

    p{ line-height:20px; } line-height : normal | length 参数: normal : 默认行高length : 百分比数字 | 由浮点数字和单位标识符组成 ...

  4. SEO前端优化

    精减代码 清除网页中一些冗余的代码,网上有这样的工具,可以辅助完成,如果需要的话,我们可以把代码中的注释去掉,甚至空行之类的也去掉,尽量的减少代码量,从而减小页面体积. CSS Sprites 通俗点 ...

  5. .Net Core 项目中的包引用探索(使用VSCode)

    本文组织有点乱,先说结论吧: 1 在 project.json 文件中声明包引用. 而不是像以前那样可以直接引用 dll. 2 使用 dotnet restore 命令后,nuget 会把声明的依赖项 ...

  6. Linux一

    1,debian默认需要手动开启SSH连接# Authentication:LoginGraceTime 120PermitRootLogin without-passwordStrictModes ...

  7. ZigBee组网原理

    Zigbee组建一个完整的网络包含两个步骤:网络初始化和节点加入网络.其中,节点加入网络可以分为通过协调器直接连接入网和通过已有父节点入网.下面来依次说明. 1. 网络初始化 ZigBee网络初始化只 ...

  8. Poj 3239 Solution to the n Queens Puzzle

    1.Link: http://poj.org/problem?id=3239 2.Content: Solution to the n Queens Puzzle Time Limit: 1000MS ...

  9. 在asp.net mvc中如何使用Grid++ Report (锐浪报表)

    在asp.net mvc中如何使用Grid++ Report (锐浪报表) 在cshtml,razor中的处理方法 以官方的asp.net(csharp)中的第一个示例"1a.简单表格&qu ...

  10. Spark Streaming揭秘 Day27 Job产生机制

    Spark Streaming揭秘 Day27 Job产生机制 今天主要讨论一个问题,就是除了DStream action以外,还有什么地方可以产生Job,这会有助于了解Spark Streaming ...