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