PowerShell detection registry key value judgment

Source: Internet
Author: User

PowerShell has been learning, scripting ability is limited, all based on their own logical thinking to write. If there is a master please leave a message pointing.


Encounter a case in the work:

You need to add a registry key to determine if there is a display present. 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
$reg 1 = "Hklm:\software\microsoft\windows\currentversion\policies\system"
$text 1 = Get-content-path C:\tools01\temp.txt
$test 2 = $text 1-cmatch ' localaccounttokenfilterpolicy '
$test 3 = "Localaccounttokenfilterpolicy:1"
#echo $test 2
if ($test 2-contains $test 3) {echo exists localaccounttokenfilterpolicy}
else {new-itemproperty $reg 1-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. Determines whether the text contains the key value to be added, and if so, the display exists and is not added.

Hope that the Danale to spray ...

This article is from the "Cheng Zi" blog, make sure to keep this source http://jif521.blog.51cto.com/848361/1891155

PowerShell detection registry key values

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.