Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Determination of key value of powershell detection registry

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Powershell has been learning, the script writing ability is limited, all rely on their own logic to write. If there is a master, please leave a message and give me advice.

Come across a case at work:

You need to add a registry key to determine if it exists. If not, add a key value.

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 exists LocalAccountTokenFilterPolicy}

Else {New-ItemProperty $reg1-Name "LocalAccountTokenFilterPolicy"-Value "1"-PropertyType dword}

# Get-ItemProperty "HKLM:\ Software\ Microsoft\ Windows\ CurrentVersion\ Policies\ System"

Idea: check all key values in the registry directory and import them into text. Determine whether the text contains the key value to be added, and if so, it shows that it exists, and if not, add it.

I hope the big shots will spray it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report