目录
一、客户端执行放在共享文件夹得bat,powershell脚本
一、客户端执行放在共享文件夹得bat,powershell脚本
1.共享文件夹建议设置仅部分人可维护文件权限
2.编辑组策略修改所有客户端允许脚本执行权限
二、计划任务分发执行脚本,不显示弹窗
例如:
-windowstyle hidden -file \\10.10.123.123\jiaob\software-hz.ps1
\\10.10.123.123\jiaob
其中 -windowstyle hidden -file 前缀会让powershell脚本在客户端执行时一闪而过。防止因窗口显示时人为关闭造成未执行
三、cmd脚本不显示窗口
需要使用vbs脚本调用cmd命令,例如:
创建文本文档重命名为1.vbs,复制如下命令,将路径C:\AutoBackup.bat 部分修改为你自己得
set ws=wscript.createobject("wscript.shell")
ws.run "C:\AutoBackup.bat /start",0
四、users账户允许安装仅管理员可安装软件脚本
创建文本文件重命名为1.vbs 可以使用Vbs To Exe 将vbs打包成exe文件
option explicit
dim Name,fs,ts,WshShell
set fs=createobject("scripting.filesystemobject")
set ts=fs.opentextfile("\\10.10.128.128\1\Document.txt",1,true)
Name=ts.readline
Set WshShell = CreateObject("WScript.Shell")
WshShell.run "cmd /k title key"
wscript.Sleep 1000
WshShell.AppActivate("key")
WshShell.SendKeys "@ECHO OFF{Enter}"
WshShell.SendKeys "runas /user:vdi@vdi.huawei.com \\10.10.128.128\Software\VPN\univpn-win-full\univpn-win-full.exe{Enter}"
wscript.Sleep 500
WshShell.SendKeys Name
WshShell.SendKeys "{Enter}"
五、windows开关机脚本
1 开机后自动执行脚本
脚本拷贝到 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp 在每次用户登录时执行脚本
2 组策略开关机执行脚本
需要在浏览中弹出得路径目录下需要拷贝进去脚本
六、备份脚本
# 将数据通过robocopy命令备份到共享文件夹中,判断备份命令返回码和关键词robocopyAutoBackUpEnded确认是否执行成功,以及是否需要再次执行备份。通过年月日得截取和除法求余可以改为指定间隔月或日进行备份 改为python实现会更强大
@echo off
cd C:\
set date=%DATE:~2,2%%DATE:~5,2%
net use \\10.10.128.128 backup3 /user:backup3
set SouP=C:\Users\Administrator\Desktop\20241217
set TarPash=\\10.10.128.128\shiyanshi\qita\RD-JS-1111-G-J_%COMPUTERNAME%_%date%\20241217
set logfile=\\10.10.128.128\shiyanshi\qita\RD-JS-1111-G-J_%COMPUTERNAME%_%date%\AutoBackupLOG.txt
if not exist %TarPash% (
mkdir %TarPash%
)
set /a BFnum = 9
find /C "robocopyAutoBackUpEnded" %logfile%
if %ERRORLEVEL% NEQ 0 (
robocopy %SouP% %TarPash% /mir /R:1 /w:5 /LOG+:%logFile% /bytes /np /nfl /x
if %ERRORLEVEL% lss 8 (
set /a BFnum = %ERRORLEVEL%
)
)
find /C "32 (0x00000020)" %logfile%
set /a FindNum1 = %ERRORLEVEL%
if %BFnum% lss 8 (
if %FindNum1% NEQ 0 (
echo robocopyAutoBackUpEnded >>%logFile%
)
)
net use \\10.10.100.99 /delete /y
七、获取软件列表脚本
获取安装软件并写入共享文件夹中已计算机名命名得文本文件
$FYear = (Get-Date).Year
$FMonth = (Get-Date).ToString("MM") # 直接格式化为两位数的月份
$FDay = (Get-Date).Day
# 构造路径
$path1 = "$FYear$FMonth" # 使用字符串插值简化拼接
$path2 = "\\10.10.112.112\00\hz\$path1\"
# 获取当前日期(格式为:年月日)
$currentDate = Get-Date -Format "yyyyMMdd"
# 获取当前用户信息
$currentUser = whoami
$wdd =hostname
# 合并系统和个人的卸载信息
$installedSoftware = @()
$installedSoftware += Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" |
Where-Object { $_.DisplayName -ne $null }
$installedSoftware += Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
Where-Object { $_.DisplayName -ne $null }
# 创建一个新的字符串集合,包含拼接后的结果
$formattedResults = foreach ($software in $installedSoftware) {
# 清理 DisplayName 中的多余字符(如 "**")
$cleanedName = $software.DisplayName -replace '\*+', '' # 移除所有连续的 "*"
$cleanedName = $cleanedName.Trim() # 去掉前后空白字符
# 拼接成 "年月日*whoami值*软件名称" 格式
if (-not [string]::IsNullOrWhiteSpace($cleanedName)) {
"$currentDate*$currentUser*$cleanedName"
}
}
# 输出结果
$formattedResults >> $path2\$wdd.txt
八、获取计算机信息脚本
cd C:\
net use \\10.10.112.112 Qwer4321 /user:vdi\skuser
$w = whoami
$wd = hostname
#wmic bios get serialnumber
#获取设备品牌序列号型号
$model =wmic CSPRODUCT get name,vendor,version,identifyingnumber
$wdd =$wd +"*" + $w +"*" + $model >>\\10.10.110.138\00\Systeminfo\model.txt
#获取设备系统激活状态
$active=cscript C:\Windows\System32\slmgr.vbs /dli
$wdd3= $wd +"*" +$w + "*" + $active>> \\10.10.110.138\00\Systeminfo\active.txt
#获取内存信息
#wmic memorychip get Manufacturer,DeviceLocator,Caption,Capacity,PartNumber,FormFactor,BankLabel,SMBIOSMemoryType,MemoryType,speed,ConfiguredClockSpeed,name