saltstack远程操作WINDOWS的POWERSHELL脚本

简介:

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

 

直接在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)
复制代码
目录
相关文章
|
1月前
|
Unix Shell Windows
Windows PowerShell技巧:使用findstr实现类似grep的功能
显示带有线路编号**: `/N`选项将显示每条结果前面带有其在线路上出现位置编号。
336 7
|
1月前
|
存储 Windows
Windows PowerShell操作:如何删除环境变量
此外,还有一些第三方工具可以用来管理环境变量,这些工具通常提供了更为用户友好的界面来添加、编辑或删除环境变量,但是使用PowerShell可以更直接地控制这些设置,并且可以很容易地集成到脚本中以自动化环境配置的管理。
293 7
|
9月前
|
JavaScript Shell C#
多种脚本批量下载 Docker 镜像:Shell、PowerShell、Node.js 和 C#
本项目提供多种脚本(Shell、PowerShell、Node.js 和 C#)用于批量下载 Docker 镜像。配置文件 `docker-images.txt` 列出需要下载的镜像及其标签。各脚本首先检查 Docker 是否安装,接着读取配置文件并逐行处理,跳过空行和注释行,提取镜像名称和标签,调用 `docker pull` 命令下载镜像,并输出下载结果。使用时需创建配置文件并运行相应脚本。C# 版本需安装 .NET 8 runtime。
594 3
【Azure App Service】PowerShell脚本批量添加IP地址到Web App允许访问IP列表中
Web App取消公网访问后,只允许特定IP能访问Web App。需要写一下段PowerShell脚本,批量添加IP到Web App的允许访问IP列表里!
200 2
|
Windows
Powershell 重新排列去重 Windows环境变量
【9月更文挑战第13天】本文介绍如何使用PowerShell对Windows环境变量进行重新排列和去重。首先通过`$env:`访问环境变量,接着使用`-split`命令分割路径,再利用`Select-Object -Unique`去除重复项。之后可根据需要对路径进行排序,最后将处理后的路径组合并更新环境变量。注意修改环境变量前应备份重要数据并了解潜在影响。
394 10
|
Python Windows
python之windows脚本启动bat
python之windows脚本启动bat
|
监控 关系型数据库 MySQL
PowerShell 脚本编写 :自动化Windows 开发工作流程
PowerShell 脚本编写 :自动化Windows 开发工作流程
507 0
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
103 3
|
安全 Shell Linux
内网渗透测试基础——Windows PowerShell篇
内网渗透测试基础——Windows PowerShell篇
499 0
|
数据安全/隐私保护
【Azure Entra ID】使用PowerShell脚本导出Entra ID中指定应用下的所有用户信息
在Azure Entra ID中,需要导出一个Application 下的用户信息, 包含User的创建时间。
216 0

热门文章

最新文章

推荐镜像

更多