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)
复制代码
目录
相关文章
|
5天前
|
监控 关系型数据库 MySQL
PowerShell 脚本编写 :自动化Windows 开发工作流程
PowerShell 脚本编写 :自动化Windows 开发工作流程
12 0
|
1月前
|
Python Windows
python之windows脚本启动bat
python之windows脚本启动bat
|
1月前
|
Windows
Powershell 重新排列去重 Windows环境变量
【9月更文挑战第13天】本文介绍如何使用PowerShell对Windows环境变量进行重新排列和去重。首先通过`$env:`访问环境变量,接着使用`-split`命令分割路径,再利用`Select-Object -Unique`去除重复项。之后可根据需要对路径进行排序,最后将处理后的路径组合并更新环境变量。注意修改环境变量前应备份重要数据并了解潜在影响。
103 10
|
17天前
|
安全 Shell Linux
内网渗透测试基础——Windows PowerShell篇
内网渗透测试基础——Windows PowerShell篇
67 0
|
18天前
|
数据安全/隐私保护
【Azure Entra ID】使用PowerShell脚本导出Entra ID中指定应用下的所有用户信息
在Azure Entra ID中,需要导出一个Application 下的用户信息, 包含User的创建时间。
|
2月前
【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
|
2月前
|
安全 Shell Windows
记windows自定义bat脚本自启动
【8月更文挑战第27天】在Windows系统中,可让自定义bat脚本自启动的方法有两种:一是利用“启动”文件夹,通过创建bat脚本的快捷方式并将其放置于该文件夹;二是使用任务计划程序,创建一个启动时触发的任务来运行bat脚本。需确保脚本正确安全,避免对系统产生不良影响。
|
2月前
|
Ubuntu Linux 测试技术
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
|
2月前
|
存储 Shell 容器
【Azure 存储服务】使用PowerShell脚本创建存储账号(Storage Account)的共享访问签名(SASToken) : New-AzStorageContainerSASToken
【Azure 存储服务】使用PowerShell脚本创建存储账号(Storage Account)的共享访问签名(SASToken) : New-AzStorageContainerSASToken
|
2月前
【Azure 应用服务】Azure Function 中运行Powershell 脚本,定位 -DefaultProfile 引发的错误
【Azure 应用服务】Azure Function 中运行Powershell 脚本,定位 -DefaultProfile 引发的错误