powershell检测注册表键值判断

Powershell一直在学习中,脚本编写能力有限,全凭自己的逻辑思路去写。如果有高手请留言指点。

在工作中碰到一个案例:

需要添加一个注册表项,判断如果有,显示存在。如果没有,添加键值。

New-Item -Path C:\tools01 -ItemType directory -Force
Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System" > C:\tools01\temp.txt
$reg1 = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System"
$text1 = Get-Content -Path C:\tools01\temp.txt
$test2 = $text1 -cmatch ‘LocalAccountTokenFilterPolicy‘
$test3 = "LocalAccountTokenFilterPolicy   : 1"
#echo $test2
if ($test2 -contains $test3){echo 存在LocalAccountTokenFilterPolicy}
else {New-ItemProperty $reg1 -Name "LocalAccountTokenFilterPolicy" -Value "1" -PropertyType dword }
#Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System"

思路:检查注册表目录下所有键值并导入到文本。判断文本中是否包含要添加的键值,如果有,就显示存在,没有就添加。

希望大拿们来喷……

时间: 2024-08-19 09:35:05

powershell检测注册表键值判断的相关文章

Ubuntu - Dconf 注册表键值修改参考表

gsettings reset org.gnome.desktop.wm.preferences theme默认gnomegsettings set org.gnome.desktop.interface clock-show-date true顶部面板显示日期gsettings set org.gnome.SessionManager logout-prompt 'false'禁止注销重关机启延时gsettings set org.gnome.desktop.interface cursor-

windbg脚本实践2----监控特定注册表键值创建和删除

在Cmxxkey层面下断点,配合bp /t (/p)  命令可以监控指定线程 进程 对指定注册表键值的创建和删除. $$***************************************************************** $$ Script by kms_hhl to monitor regvalue delete set $$ Create Time 2014_11 $$ Execute by $$><D:\BaiduYunTongBu\百度云同步盘\windb

查询、创建、设置注册表键值的示例代码

示例代码将在注册表位置:HKEY_CURRENT_USER\Software\  读写键值 bool LicenseManage::OpenRegKey(HKEY& hRetKey) { if (ERROR_SUCCESS == RegOpenKey(HKEY_CURRENT_USER,"Software", &hRetKey)) { return true; } return false; } bool LicenseManage::CreateRegKey(stri

注册表键值明明存在OpenSubKey始终返回null,解决方案

先上代码及实例 RegistryKey rsg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Macromedia\FlashPaper Printer\2\Installation\", false);为什么返回值是NULL L 原因其实是在64位电脑上跑32位程序,以上代码读取为空值,32位电脑读注册表使用OpenSubKey是正确的 解决方法: I will show you how to get connecting string

RegQueryValueEx检索一个已打开的注册表句柄中,指定的注册表键的类型和设置值。

1VC声明 1 2 3 4 5 6 7 8 LONG RegQueryValueEx(     HKEY hKey,            // handle to key     LPCTSTR lpValueName,  // value name     LPDWORD lpReserved,   // reserved     LPDWORD lpType,       // type buffer     LPBYTE lpData,        // data buffer    

如何查询注册表的值及 Powershell 应用

利用 c:\windows\system32\reg.exe 的 query 参数即可. reg.exe 的参数如下: C:\windows\system32> reg.exe /?REG Operation [Parameter List]  Operation  [ QUERY   | ADD    | DELETE  | COPY    | SAVE    | LOAD   | UNLOAD  | RESTORE | COMPARE | EXPORT | IMPORT  | FLAGS ]

powershell通过注册表路径判断系统是否需要重启

因为系统的补丁更新,需要重启服务器,因为服务器当前有用户在远程登录使用当中,但是又不想一直值守在电脑跟前,所以可以通过脚本定时检查系统状态如果系统因为补丁更新需要重启服务器,在安装完补丁之后,会临时创建一个需要重启的注册表路径,等待系统重启完成之后,此路径则会删除,废话不多说直接展示代码示例$path = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired'Test-Pa

RegOpenKeyEx 打开一个指定的注册表键

LONG RegOpenKeyEx( HKEY hKey, // 需要打开的主键的名称 LPCTSTR lpSubKey, //需要打开的子键的名称 DWORD ulOptions, // 保留,设为0 REGSAM samDesired, // 安全访问标记,也就是权限 PHKEY phkResult // 得到的将要打开键的句柄 ) hKey [输入] 当前打开或者以下预定义的键. HKEY_CLASSES_ROOT HKEY_CURRENT_USER HKEY_LOCAL_MACHINE

用 PowerShell 读写注册表

HKEY_CURRENT_CONFIG\test\SideBySide\Winners\amd64_.netframework_31bf3856ad364e35_none_f5dd4e94975c8e4e value="amd64.netframework31bf3856ad364e35nonef5dd4e94975c8e4e"functionResolve?Winners(value ) { $base = "HKCU:\test\SideBySide\Winners\&q