39 Star 222 Fork 51

chuanjiao10 / kasini3000

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
k_run_ip.ps1 7.25 KB
一键复制 编辑 原始数据 按行查看 历史
#建议保存编码为:bom头 + utf8
param
(
[ValidateNotNullOrEmpty()]
[Alias("ipaddress")][String]$被控机ip地址 = ${global:当前被控机_ip}.ip,
[Alias('file','脚本文件名')][String]$ps1脚本文件名,
[parameter(Position = 0)][Alias("scriptblock")][scriptblock]$powershell代码块 = { },
[Alias("allparameter")]$全部传入参数,
$复制主控机node_script目录到被控机 = $false,
[ValidateSet('microsoft.powershell','powershell.7')]
[string]$ConfigurationName = 'microsoft.powershell'
)
function yg严格测试布尔型变量($被测试的布尔形变量)
{
if (($被测试的布尔形变量 -eq 1) -or ($被测试的布尔形变量 -eq $true) -or ($被测试的布尔形变量 -eq 'true'))
{
return $true
}
elseif (($被测试的布尔形变量 -eq 0) -or ($被测试的布尔形变量 -eq $false) -or ($被测试的布尔形变量 -eq 'false'))
{
return $false
}
else
{
Write-Error '错误:不合法的布尔型值,错误码999'
exit 999
}
}
[bool]$复制主控机node_script目录到被控机 = yg严格测试布尔型变量 $复制主控机node_script目录到被控机
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
& 'c:\ProgramData\kasini3000\0k_source.ps1'
}
if ($IsLinux -eq $True)
{
& '/etc/kasini3000/0k_source.ps1'
}
Write-Verbose '开始在【被控机ip】上执行'
& 'zd只读nodelist文件.ps1'
$private:当前被控机 = $global:所有被控机 | Where-Object { $_.ip -eq $被控机ip地址 }
if ($private:当前被控机.ip -ne $被控机ip地址)
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "nodelist文件中找不到这个ip地址: ${被控机ip地址} ,错误码11"
}
else
{
Write-Error "NODE IP was not found in the NODELIST file: ${被控机ip地址} ,error code 11"
}
$private:当前被控机.'被控机os类型' = '错误:nodelist文件中找不到这个ip地址'
exit 11
}
$win = 'win7','win8','win10','win11','win2008r2','win2012r2','win2016','win2019','win2022'
$linux = & "${PSScriptRoot}/linux_distribution_str.ps1"
$all = $win + $linux
Write-Verbose $private:当前被控机.被控机os类型
Write-Verbose $private:当前被控机.ip
if ($private:当前被控机.被控机os类型 -notin $all)
{
& 'sx1刷新单个被控机对象的_os类型属性.ps1' -被控机ip地址 $private:当前被控机.ip
}
Write-Verbose $private:当前被控机.被控机os类型
if ($private:当前被控机.被控机os类型 -notin $all)
{
Write-Error ("错误:当前被控机【{0}】,【端口不通】或【账户密码不对】。任务无法运行。退出码4" -f $private:当前被控机.ip)
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
& "${global:kasini3000目录}\admin_gui\pic\bc随机报错背景图片.ps1"
}
exit 4
}
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Host "`nip:" -ForegroundColor Cyan -NoNewline
Write-Host $global:当前被控机_ip.ip -ForegroundColor Yellow -NoNewline
Write-Host " 被控机名:" -ForegroundColor Cyan -NoNewline
Write-Host $global:当前被控机_ip.被控机显示名 -ForegroundColor Yellow -NoNewline
Write-Host " 被控机os:" -ForegroundColor Cyan -NoNewline
Write-Host $global:当前被控机_ip.被控机os类型 -ForegroundColor Yellow
}
else
{
Write-Host "`nip:" -ForegroundColor Cyan -NoNewline
Write-Host $global:当前被控机_ip.ip -ForegroundColor Yellow -NoNewline
Write-Host " name:" -ForegroundColor Cyan -NoNewline
Write-Host $global:当前被控机_ip.被控机显示名 -ForegroundColor Yellow -NoNewline
Write-Host " os:" -ForegroundColor Cyan -NoNewline
Write-Host $global:当前被控机_ip.被控机os类型 -ForegroundColor Yellow
}
if ( ($IsWindows -eq $True) -or ($PSVersionTable.psversion.major -lt 6) ) #win
{
if ( $private:当前被控机.被控机os类型 -in $win)
{
if ( $private:当前被控机.端口 -eq '')
{
& 'run_win2win5985_pwd.ps1' -目的ip地址 $private:当前被控机.ip -powershell代码块 $powershell代码块 -ps1脚本文件名 $ps1脚本文件名 -传入参数 $全部传入参数 -复制主控机node_script目录到被控机 $复制主控机node_script目录到被控机 -ConfigurationName $ConfigurationName
}
else
{
& 'run_win2win5985_pwd.ps1' -目的ip地址 $private:当前被控机.ip -powershell代码块 $powershell代码块 -ps1脚本文件名 $ps1脚本文件名 -传入参数 $全部传入参数 -端口 $private:当前被控机.端口 -复制主控机node_script目录到被控机 $复制主控机node_script目录到被控机 -ConfigurationName $ConfigurationName
}
}
if ( $private:当前被控机.被控机os类型 -in $linux)
{
if ( $private:当前被控机.端口 -eq '')
{
& 'run_win2linux_key_pwd.ps1' -目的ip地址 $private:当前被控机.ip -powershell代码块 $powershell代码块 -ps1脚本文件名 $ps1脚本文件名 -传入参数 $全部传入参数 -复制主控机node_script目录到被控机 $复制主控机node_script目录到被控机
}
else
{
& 'run_win2linux_key_pwd.ps1' -目的ip地址 $private:当前被控机.ip -powershell代码块 $powershell代码块 -ps1脚本文件名 $ps1脚本文件名 -传入参数 $全部传入参数 -端口 $private:当前被控机.端口 -复制主控机node_script目录到被控机 $复制主控机node_script目录到被控机
}
}
}
if ($IsLinux -eq $True)
{
if ( $private:当前被控机.被控机os类型 -in $win)
{
if (Test-Path -LiteralPath "${PSScriptRoot}/run_linux2win5985_pwd.ps1")
{
if ( $private:当前被控机.端口 -eq '')
{
& 'run_linux2win5985_pwd.ps1' -目的ip地址 $private:当前被控机.ip -powershell代码块 $powershell代码块 -ps1脚本文件名 $ps1脚本文件名 -传入参数 $全部传入参数 -复制主控机node_script目录到被控机 $复制主控机node_script目录到被控机 -ConfigurationName $ConfigurationName
}
else
{
& 'run_linux2win5985_pwd.ps1' -目的ip地址 $private:当前被控机.ip -powershell代码块 $powershell代码块 -ps1脚本文件名 $ps1脚本文件名 -传入参数 $全部传入参数 -端口 $private:当前被控机.端口 -复制主控机node_script目录到被控机 $复制主控机node_script目录到被控机 -ConfigurationName $ConfigurationName
}
}
else
{
if ($env:LANG -eq 'zh_CN.UTF-8')
{
Write-Error "从【linux主控机】控制【win被控机】,是收费功能。返回码 3"
}
else
{
Write-Error "Illegal IP address found in NODELIST file: ${被控机ip地址} .exit 3 "
}
exit 3
}
}
if ( $private:当前被控机.被控机os类型 -in $linux)
{
if ( $private:当前被控机.端口 -eq '')
{
& 'run_linux2linux_key_pwd.ps1' -目的ip地址 $private:当前被控机.ip -powershell代码块 $powershell代码块 -ps1脚本文件名 $ps1脚本文件名 -传入参数 $全部传入参数 -复制主控机node_script目录到被控机 $复制主控机node_script目录到被控机
}
else
{
& 'run_linux2linux_key_pwd.ps1' -目的ip地址 $private:当前被控机.ip -powershell代码块 $powershell代码块 -ps1脚本文件名 $ps1脚本文件名 -传入参数 $全部传入参数 -端口 $private:当前被控机.端口 -复制主控机node_script目录到被控机 $复制主控机node_script目录到被控机
}
}
}
Write-Verbose '结束在【被控机ip】上执行'
exit 0
PowerShell
1
https://gitee.com/chuanjiao10/kasini3000.git
git@gitee.com:chuanjiao10/kasini3000.git
chuanjiao10
kasini3000
kasini3000
master

搜索帮助