PowerShell Install toolkit(sed awk grep unzip gzip tar)
迪丽瓦拉
2025-06-01 11:09:34
0

gnuwin32 download

gnuwin32(包含上述安装包和其它)download

前提条件

  • 开启wmi,配置网卡,参考 

  创建一键安装toolkit(sed awk grep unzip gzip tar)自动化脚本

  • 实现在线下载(sed awk grep unzip gzip tar),安装,环境变量,删除,企业微信机器人通知。
  • Expand-Archive #解压文件
  • Start-Process # 安装,等待安装完成在执行下一个
  • Rename-Item #重命名文件夹参考
  • "C:\Program Files\" #安装位置(sed awk grep unzip gzip tar)
  • 更改脚本段信息$webhook = #企业微信机器人地址,用法参考
  • Remove-Item #删除单一文件,删除批量文件参考 
powershell-install-toolkit.ps1
<# Powershell Install toolkit
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+  _____                       _____ _          _ _ +
+ |  __ \                     / ____| |        | | |+
+ | |__) |____      _____ _ _| (___ | |__   ___| | |+
+ |  ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | |  | (_) \ V  V /  __/ |  ____) | | | |  __/ | |+
+ |_|   \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++# Powershell Install toolkit
# .\powershell-install-toolkit.ps1
#>$drive="c:\"
$catalogue_site="C:\Program Files\"$grep_url="https://nchc.dl.sourceforge.net/project/gnuwin32/grep/2.5.4/"
$grep_zip="grep-2.5.4-bin.zip"
$grep_new="grep"$awk_url="https://nchc.dl.sourceforge.net/project/gnuwin32/gawk/3.1.6-1/"
$awk_zip="gawk-3.1.6-1-bin.zip"
$awk_new="awk"$sed_url="https://nchc.dl.sourceforge.net/project/gnuwin32/sed/4.2.1/"
$sed_zip="sed-4.2.1-bin.zip"
$sed_new="sed"$tar_url="https://nchc.dl.sourceforge.net/project/gnuwin32/tar/1.13-1/"
$tar_zip="tar-1.13-1-bin.zip"
$tar_new="tar"$gzip_url="https://nchc.dl.sourceforge.net/project/gnuwin32/gzip/1.3.12-1/"
$gzip_zip="gzip-1.3.12-1-bin.zip"
$gzip_new="gzip"$unzip_url="https://nchc.dl.sourceforge.net/project/gnuwin32/unzip/5.51-1/"
$unzip_zip="unzip-5.51-1-bin.zip"
$unzip_new="unzip"Write-Host "create grep sed tar awk directory" -ForegroundColor Green
New-Item -ItemType Directory $catalogue_site$grep_new
New-Item -ItemType Directory $catalogue_site$awk_new
New-Item -ItemType Directory $catalogue_site$sed_new
New-Item -ItemType Directory $catalogue_site$tar_new
New-Item -ItemType Directory $catalogue_site$gzip_new
New-Item -ItemType Directory $catalogue_site$unzip_newWrite-Host "download grep" -ForegroundColor Green
wget -Uri  $grep_url\$grep_zip -UseBasicParsing -OutFile $drivec\$grep_zipWrite-Host "download awk" -ForegroundColor Green
wget -Uri  $awk_url\$awk_zip -UseBasicParsing -OutFile $drivec\$awk_zipWrite-Host "download sed" -ForegroundColor Green
wget -Uri  $sed_url\$sed_zip -UseBasicParsing -OutFile $drivec\$sed_zipWrite-Host "download tar" -ForegroundColor Green
wget -Uri  $tar_url\$tar_zip -UseBasicParsing -OutFile $drivec\$tar_zipWrite-Host "download gzip" -ForegroundColor Green
wget -Uri  $gzip_url\$gzip_zip -UseBasicParsing -OutFile $drivec\$gzip_zipWrite-Host "download unzip" -ForegroundColor Green
wget -Uri  $unzip_url\$unzip_zip -UseBasicParsing -OutFile $drivec\$unzip_zipWrite-Host "decompression grep awk sed tar" -ForegroundColor Green
Expand-Archive -Path $drive\$grep_zip -DestinationPath $catalogue_site$grep_new
Expand-Archive -Path $drive\$awk_zip -DestinationPath $catalogue_site$awk_new
Expand-Archive -Path $drive\$sed_zip -DestinationPath $catalogue_site$sed_new
Expand-Archive -Path $drive\$tar_zip -DestinationPath $catalogue_site$tar_new
Expand-Archive -Path $drive\$unzip_zip -DestinationPath $catalogue_site$unzip_new
Expand-Archive -Path $drive\$gzip_zip -DestinationPath $catalogue_site$gzip_newWrite-Host "grep awk sed tar system path" -ForegroundColor Green
$env:path += ";C:\Program Files\grep\bin"
$env:path += ";C:\Program Files\awk\bin"
$env:path += ";C:\Program Files\sed\bin"
$env:path += ";C:\Program Files\tar\bin"
$env:path += ";C:\Program Files\gzip\bin"
$env:path += ";C:\Program Files\unzip\bin"
setx PATH $env:path /MWrite-Host "check awk version" -ForegroundColor Green
awk --version | awk  -F "Awk" '{print $2}' | awk '!/^$/'Write-Host "check sedversion" -ForegroundColor Green
(Get-Item "C:\Program Files\sed\bin\sed.exe").VersionInfo.FileVersionWrite-Host "check tar version" -ForegroundColor Green
(Get-Item "C:\Program Files\tar\bin\tar.exe").VersionInfo.FileVersionWrite-Host "check grep version" -ForegroundColor Green
(Get-Item "C:\Program Files\grep\bin\grep.exe").VersionInfo.FileVersionWrite-Host "check unzip version" -ForegroundColor Green
(Get-Item "C:\Program Files\unzip\bin\unzip.exe").VersionInfo.FileVersionWrite-Host "check gzip version" -ForegroundColor Green
(Get-Item "C:\Program Files\gzip\bin\gzip.exe").VersionInfo.FileVersionWrite-Host "delete toolkit software package" -ForegroundColor Green
Remove-Item -Path "C:\*.zip*" -Recurse#Enterprise wechat robot address
$webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXXXX"#Obtain the Windows host system version
$Win_version = Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty Caption
$Win_version_Names = echo $Win_version#Get all IP addresses of the local host
$Win_ip = foreach($ipv4 in (ipconfig) -like '*IPv4*') { ($ipv4 -split ' : ')[-1]}#Get the host name
$Win_hostname = Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty Name#Gets the current host time
$Win_time = Get-Counter '\Processor(_Total)\% Processor Time' | Select-Object -ExpandProperty Timestamp$awk_version=awk --version | awk  -F "Awk" '{print $2}' | awk '!/^$/'
$sed_version=(Get-Item "C:\Program Files\sed\bin\sed.exe").VersionInfo.FileVersion
$tar_vsersion=(Get-Item "C:\Program Files\tar\bin\tar.exe").VersionInfo.FileVersion
$grep_version=(Get-Item "C:\Program Files\grep\bin\grep.exe").VersionInfo.FileVersion
$unzip_vsersion=(Get-Item "C:\Program Files\unzip\bin\unzip.exe").VersionInfo.FileVersion
$gzip_version=(Get-Item "C:\Program Files\gzip\bin\gzip.exe").VersionInfo.FileVersion$content = Write-Output ""Win_version: $Win_version_Names" `n "Win_host_ip: $Win_ip" `n "Win_hostname: $Win_hostname" `n "awk_version: $awk_version" `n "sed_version: $sed_version" `n "tar_vsersion: $tar_vsersion" `n "grep_version: $grep_version" `n "unzip_vsersion: $unzip_vsersion" `n "gzip_version: $gzip_version" `n "Win_time: $Win_time""$body = "{`"msgtype`":`"text`",`"text`":{`"content`":`"$content`",`"mentioned_list`":[`"jason`"]}
}"Write-Host "The variable value obtained is transferred to the enterprise wechat robot" -ForegroundColor Green
Invoke-RestMethod $webhook -ContentType "application/json;charset=utf-8" -Method Post -Body $body

执行安装

.\powershell-install-toolkit.ps1

输出结果展示 

企业微信机器人安装完成通知

相关内容