前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >制作镜像前建议以管理员身份分段执行如下代码净化镜像

制作镜像前建议以管理员身份分段执行如下代码净化镜像

原创
作者头像
Windows技术交流
修改2022-05-14 14:37:06
9291
修改2022-05-14 14:37:06
举报
文章被收录于专栏:Windows技术交流Windows技术交流

黑石或其他物理机除外,仅限普通云服务器,简单点的话,就是能访问公网的≥2016的高版本系统,以管理员身份打开powershell命令行执行这2句命令即可

wget http://windowscq-1251783334.cos.ap-chongqing.myqcloud.com/xuanwoimg.ps1 -outfile c:\youhuaimg.ps1

c:\youhuaimg.ps1

后面的可以不用看了,是我给自己写的笔记。

下面命令有用到cleanmgr.exe,≥2016的系统默认有,2012和2012R2默认没有,需要管理员身份powershell执行:

Install-WindowsFeature Desktop-Experience

安装完角色后重启机器后就有cleanmgr.exe命令了。关于cleanmgr,参考

https://support.appliedi.net/kb/how-to-enable-the-disk-cleanup-tool-on-windows-server-2008-r2/

https://www.partition-magic-server.com/windows-server-2012/enable-install-disk-cleanup.html

接下来就是分段执行命令

【第1段】

首先,管理员身份cmd命令行执行这几句命令卸载TAT

sc stop tatsvc

sc delete tatsvc

wmic process where name='tat_agent.exe' call terminate

rd /s /q "C:\Program Files\qcloud\tat_agent"

#【第2段】

powershell

cmd.exe /c del /F /Q C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\*.automaticDestinations-ms 2>$null

或者下面几句命令

cd "C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations"

del *.automaticDestinations-ms

cmd.exe /c del /F /Q C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Recent\* 2>$null

cd c:\

#【第3段干掉洋葱组件】

powershell

sc.exe stop winagent 2>$null 1>$null

sc.exe config winagent start= disabled 2>$null 1>$null

sc.exe delete winagent 2>$null 1>$null

schtasks.exe /delete /tn "WinAgentKeepAlive" /F 2>$null 1>$null

#【第4段关闭云监控、云安全服务】

powershell

stop-service BaradAgentSvc 2>$null 1>$null

stop-service StargateSvc 2>$null 1>$null

stop-service YDLive 2>$null 1>$null

stop-service YDService 2>$null 1>$null

#【第5段清理老的日志】

powershell

del "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\log\cloudbase-init.log" 2>$null 1>$null

del "C:\Program Files\QCloud\Logs\*" 2>$null 1>$null

del "C:\Program Files\QCloud\Monitor\Barad\logs\*" 2>$null 1>$null

del "C:\Program Files\QCloud\Stargate\logs\*" 2>$null 1>$null

del "C:\Program Files\QCloud\YunJing\log\*" 2>$null 1>$null

#【第6段处理部分注册表】

powershell

reg delete "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v "DontDisplayLastUserName" /f 2>&1 > $null

reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles" /f 2>&1 > $null

#reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Cloudbase Solutions" /f 2>&1 > $null

#reg add "HKLM\SYSTEM\ControlSet001\Services\cloudbase-init" /v "start" /d 4 /t REG_DWORD /f

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Network\NewNetworkWindowOff" /f 2>&1 > $null

#【第7段调用cleanmgr自动清理】

powershell

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Delivery Optimization Files" /v StateFlags6550 /t REG_DWORD /d 2 /f

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\DownloadsFolder" /v StateFlags6550 /t REG_DWORD /d 2 /f

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files" /v StateFlags6550 /t REG_DWORD /d 2 /f

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin" /v StateFlags6550 /t REG_DWORD /d 2 /f

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files" /v StateFlags6550 /t REG_DWORD /d 2 /f

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup" /v StateFlags6550 /t REG_DWORD /d 2 /f

cleanmgr /sagerun:6550

reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Delivery Optimization Files" /v StateFlags6550 /f

reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\DownloadsFolder" /v StateFlags6550 /f

reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files" /v StateFlags6550 /f

reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin" /v StateFlags6550 /f

reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files" /v StateFlags6550 /f

reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup" /v StateFlags6550 /f

#【第8段调用cleanmgr自动清理】

cmd

rd /s /q %SYSTEMDRIVE%\Windows\Temp 2>nul 1>nul

rd /s /q "%SYSTEMDRIVE%\Windows\Downloaded Program Files" 2>nul 1>nul

rd /s /q %SYSTEMDRIVE%\$Recycle.bin 2>nul 1>nul

%SYSTEMDRIVE%\Windows\System32\cleanmgr.exe /d C /verylowdisk 2>nul 1>nul

%SYSTEMDRIVE%\Windows\System32\cleanmgr.exe /d C /autoclean 2>nul 1>nul

#【第9段检查是否有组件损坏】

powershell

dism /online /cleanup-image /scanhealth

#【第10段清理日志】

powershell

#reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Cloudbase Solutions" /f 2>&1 > $null

reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles" /f 2>&1 > $null

reg delete "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation" /v "RealTimeIsUniversal" /f 2>&1 > $null

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Network\NewNetworkWindowOff" /f 2>&1 > $null

wevtutil el | Foreach-Object {wevtutil cl "$_" 2>$null}

wevtutil cl security 2>$null

wevtutil cl system 2>$null

手动关机做镜像

注意,如果是制作sysprep镜像,建议在执行sysprep命令前,执行这句命令,即在执行sysrep关机之前, 要把cloudbase服务设置为手动或禁用状态.

reg add "HKLM\SYSTEM\ControlSet001\Services\cloudbase-init" /v "start" /d 4 /t REG_DWORD /f

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档