PowerShell 批量部署windows_exporter到所有Windows主机

news2024/9/19 22:07:38

  

前提条件 参考

批量拷贝脚本到远程主机

  • $local_path="D:\PowerShell\Powershell-Windows_Admin_Center-install\" #本地脚本存放目录
  • $Destination="d:\" #本地拷贝的脚本到目标主机的目录
  • Invoke-Command -filepath D:\powershell-install-windows_exporter-0.20.ps1 -ComputerName $server -Credential $cred #此处是直接执行本地代码生效到目标主机,此处我注释了,需要此案例的可以启用注释掉下方invoke-expression段
  • invoke-expression -command D:\powershell-install-windows_exporter-0.20.ps1 #此处执行的是拷贝到目标主机上的脚本,替换成你自己的脚本名称
  • $user="administrator" #用户,必须是管理员
  • $password=ConvertTo-SecureString "YOU_password" -AsPlainText -Force #用户密码
  • $cred=New-Object System.Management.Automation.PSCredential($user,$password)
  • $pchost='192.168.19.10','192.168.19.11' #主机IP,有多少填写多少,注意格式
  • $port=5985 #winrm http服务端口
powershell-Remote-Software-Installation.ps1
<# Powershell Remote Software Installation
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+  _____                       _____ _          _ _ +
+ |  __ \                     / ____| |        | | |+
+ | |__) |____      _____ _ _| (___ | |__   ___| | |+
+ |  ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | |  | (_) \ V  V /  __/ |  ____) | | | |  __/ | |+
+ |_|   \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++
                                                                                                              
# Remote Software Installation
# .\powershell-Remote-Software-Installation.ps1
#> 
 
$user="administrator"
$password=ConvertTo-SecureString "YOU_host_password" -AsPlainText -Force
$cred=New-Object System.Management.Automation.PSCredential($user,$password)
$pchost='192.168.19.10'
$port=5985
 
$local_path="D:\powershell-install-windows_exporter-0.20.ps1"
$Destination="d:\"

foreach($server in $pchost){
#Create a session with remote computer using New-Session
$Session=New-PSSession -ComputerName $server -Credential $cred

Write-Host "Log on to the host $pchost" -ForegroundColor Green
Enter-PSSession -ComputerName $server -port $port -Credential $cred

#Write-Host "Execute local script to take effect on remote server $pchost" -ForegroundColor Green
#Invoke-Command -filepath D:\powershell-install-windows_exporter-0.20.ps1 -ComputerName $server -Credential $cred

Write-Host "Use Copy-Item to copy files to a remote computer $pchost" -ForegroundColor Green
Copy-Item -Path "$local_path" -Destination $Destination -ToSession $session -Recurse

Write-Host "Execute the script directly on the server directory $pchost" -ForegroundColor Green
Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock {
invoke-expression -command D:\powershell-install-windows_exporter-0.20.ps1
 }
}

创建安装windows_exporter自动化脚本

powershell-install-windows_exporter-0.20.ps1
<# Powershell Install windows_exporter-0.20
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+  _____                       _____ _          _ _ +
+ |  __ \                     / ____| |        | | |+
+ | |__) |____      _____ _ _| (___ | |__   ___| | |+
+ |  ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | |  | (_) \ V  V /  __/ |  ____) | | | |  __/ | |+
+ |_|   \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++
                                                                                                              
# Powershell Install windows_exporter-0.20
# .\powershell-install-windows_exporter-0.20.ps1
#> 

#windows_exporter-0.20
$windows_exporter = "windows_exporter-0.20.0-amd64.msi"
$url = "https://github.com/prometheus-community/windows_exporter/releases/download/v0.20.0/"
$drive = "D:\"

Write-Host "download windows_exporter-0.20 up D dish" -ForegroundColor Green
wget -Uri $url/$windows_exporter -UseBasicParsing -OutFile $drive$windows_exporter

Write-Host "Install windows_exporter" -ForegroundColor Green 
Start-Process "D:\$windows_exporter" -ArgumentList "-qn"  -wait

Write-Host "Delete the downloaded file" -ForegroundColor Green
rm $drive$windows_exporter 

Write-Host "Restart winRM the service" -ForegroundColor Green
Restart-Service winRM

执行一键批量安装到所有主机

.\powershell-Remote-Software-Installation.ps1

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/30944.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【构建ML驱动的应用程序】第 8 章 :部署模型时的注意事项

&#x1f50e;大家好&#xff0c;我是Sonhhxg_柒&#xff0c;希望你看完之后&#xff0c;能对你有所帮助&#xff0c;不足请指正&#xff01;共同学习交流&#x1f50e; &#x1f4dd;个人主页&#xff0d;Sonhhxg_柒的博客_CSDN博客 &#x1f4c3; &#x1f381;欢迎各位→点赞…

11个步骤完美排查服务器是否被入侵

随着开源产品的越来越盛行&#xff0c;作为一个Linux运维工程师&#xff0c;能够清晰地鉴别异常机器是否已经被入侵了显得至关重要&#xff0c;个人结合自己的工作经历&#xff0c;整理了几种常见的机器被黑情况供参考&#xff1a; 背景信息&#xff1a;以下情况是在CentOS 6.…

计算机的磁盘与中断介绍

磁盘 大多数计算机都有磁盘。这只是连接到I/O总线的另一个外围设备。磁盘的任务非常简单&#xff1b;它可以做两件事&#xff1a;存储你发给它的字节&#xff0c;它发送给你之前存储的字节。 大多数计算机都有磁盘有两个原因。首先&#xff0c;它们能够存储大量字节&#xff0c…

微信小程序实现一些优惠券/卡券

背景 &#x1f44f; 前几周有小伙伴问我如何用css实现一些优惠券/卡券&#xff0c;今天就来分享一波吧&#xff01;速速来Get吧~ &#x1f947;文末分享源代码。记得点赞关注收藏&#xff01; 1.实现效果 2.实现原理 2.1 实现内凹圆角 假设我们要实现这样的一个效果&#xf…

Java八股文

2022年接近年底了&#xff0c;想必绝大多数的小伙伴跳槽的心已经蠢蠢欲动。但一边又是互联网寒冬、大厂裁员&#xff0c;导致人心惶惶&#xff0c;想跳又不敢跳。但现在罡哥&#xff0c;给大家整理了八股文大厂面试真题和面试技巧。这里免费分享给大家。 资料包括&#xff1a;…

算法day29|491,46,47

491.递增子序列 class Solution:def findSubsequences(self, nums: List[int]) -> List[List[int]]:used [False]*len(nums)result []nums.sort()def backtracking(nums,path,startindex,used):nonlocal resultif len(path)>1:result.append(path[:])for i in range(s…

云原生系列 五【轻松入门容器基础操作】

✅作者简介&#xff1a; CSDN内容合伙人&#xff0c;全栈领域新星创作者&#xff0c;阿里云专家博主&#xff0c;华为云云享专家博主&#xff0c;掘金后端评审团成员 &#x1f495;前言&#xff1a; 最近云原生领域热火朝天&#xff0c;那么云原生是什么&#xff1f;何为云原生…

C<6.1>函数习题(函数内测整形数组大小,递归

目录 1&#xff0c;数组比较 2&#xff0c;勒让德多项式 3&#xff0c;查询数组&#xff08;sizeof问题 1&#xff0c;数组比较 1. 编写函数实现比较两个长度为 n&#xff08;n 可变&#xff09;的数组大小。比较逻 辑如下&#xff1a; 假设 a 和 b 为 n 个元素的整型数组&am…

Web(一)Web前端开发概述

第1关_Web前端开发相关的概念 相关知识 为了完成本关任务&#xff0c;你需要掌握&#xff1a;1.Web系统的组成&#xff1b;2.浏览器的概念&#xff1b;3.URL的概念&#xff1b;4.Web标准。 Web系统的组成&#xff1a;Web是Internet上最受欢迎的一种多媒体信息服务系统。 整个…

【LeetCode】string 类的几道简单题

​&#x1f320; 作者&#xff1a;阿亮joy. &#x1f386;专栏&#xff1a;《阿亮爱刷题》 &#x1f387; 座右铭&#xff1a;每个优秀的人都有一段沉默的时光&#xff0c;那段时光是付出了很多努力却得不到结果的日子&#xff0c;我们把它叫做扎根 &#x1f449;仅反转字母&a…

Java源代码到用户使用都经历了哪些阶段

1、测试好的代码是如何部署给用户的。 首先&#xff1a;写好的代码通过打包生成jar包放到一个服务器上运行&#xff0c;服务器上需要有Java虚拟机&#xff0c;当然可以在存放jar包的服务器上安装数据库&#xff0c;或者把服务器放到另外一台服务器上也可以&#xff0c;但是在代…

SpringCloud-04-Feign

一、Feign介绍 Feign是一个声明式web服务客户机。它使编写web服务客户机更容易。要使用Feign创建一个接口并对其进行注释。它具有可插入注释支持&#xff0c;包括Feign注释和JAX-RS注释。Feign还支持可插式编码器和解码器。Spring Cloud增加了对Spring MVC注释的支持&#xff…

10个全球最佳免费土地覆被/土地利用数据资源

不知道大家有没有想过&#xff0c;在我们来到地球的一生时间中&#xff0c;地球会有多大的变化呢? 是在空旷的草地新建了公园&#xff0c;还是低矮的平房变成了一座座大厦? 这些林林总总的变化&#xff0c;总是令人应接不暇。然而&#xff0c;在漫长的人类历史历程中&#xf…

2022亚太数学杯数学建模竞赛A题(思路分析......)

&#x1f468;‍&#x1f393;个人主页&#xff1a;研学社的博客 &#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜…

Java数据类型:基本数据类型和引用数据类型

Java 语言是强类型语言&#xff0c;编译器存储在变量中的数值具有适当的数据类型。学习任何一种编程语言都要了解其数据类型&#xff0c;下面将详细介绍 Java 中的数据类型。 Java 语言支持的数据类型分为两种&#xff1a;基本数据类型&#xff08;Primitive Type&#xff09;…

NET CORE Configuraion 使用详解

相关配置 <Project Sdk"Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>netcoreapp3.1</TargetFramework></PropertyGroup><ItemGroup><!--读取配置的核心包--><Packa…

谷歌浏览器自定义标签页 newtab

创建一个文件夹, 里面放置信息: 其中&#xff0c; manifest.json 不能变&#xff0c; home.html 是新的标签页信息 manifest.json 内容: {"chrome_url_overrides": {"newtab": "home.html"},"manifest_version": 2,"name"…

新知实验室TRTC 初体验

引言 随着短视频行业的不断发展&#xff0c;人们对实时音视频的需求越来越多。在线直播&#xff08;秀场直播、电商直播、赛事直播、新品发布会、路演、在线拍卖&#xff09;的相关产品不断涌现&#xff0c;百花齐放。对于业务来说&#xff0c;自研开发一个实时音视频服务&…

spring boot 过滤器拦截器与aop

目录 一、过滤器 (Filter) 1.1 什么是过滤器 1.2 springboot配置过滤器 方式一&#xff1a;使用WebFilter 二、拦截器(Interceptor) 2.1 什么是拦截器 2.2 使用拦截器方法 三、拦截器&过滤器与spring aop的区别 3.1 区别 3.2添加aop 适用场景&#xff1a; 拦截…