|
| 1 | +# VARIABLES and ARRAYS |
| 2 | +# Path for Registry Settings |
| 3 | +$PSParentPath = "HKLM:\SOFTWARE\Wow6432Node" |
| 4 | +$PSChildName = "OneZeroOne" |
| 5 | +$PSPath = $PSParentPath + "\"+ $PSChildName |
| 6 | +# Array containing comma-separated lists of key values: ("Name1", "Value1", "Type1"),("Name2", "Value2", "Type2"),("Name3"...) |
| 7 | +# For value types, please see https://docs.microsoft.com/en-us/windows/win32/sysinfo/registry-value-types |
| 8 | +$RegVals = @( |
| 9 | + ("InstallationDirectory","C:\Program Files\One Zero One\","SZ"), |
| 10 | + ("Version","1.0.1","SZ"), |
| 11 | + ("LastUpdateCheck","60240c70","DWORD") |
| 12 | +) |
| 13 | + |
| 14 | +# MAIN |
| 15 | +# Test for the existence of $PSpath |
| 16 | +If ( -not (Test-Path "$PSPath") ) { |
| 17 | + # $PSPath does not exist, create it |
| 18 | + New-Item -Path "$PSParentPath" -Name "$PSChildName" |
| 19 | +} |
| 20 | + |
| 21 | +# Loop through array of ("Name", "Value", "Type") lists |
| 22 | +ForEach ($List in $RegVals) { |
| 23 | + $Name = $List[0] |
| 24 | + $Value = $List[1] |
| 25 | + $Type = $List[2] |
| 26 | + # Test for existence of Name. Will return null if it doesn't exist |
| 27 | + If ($null -eq (Get-ItemProperty -Path $PSPath).($Name)) { |
| 28 | + # Name doesn't exist and we should create it |
| 29 | + New-ItemProperty -Path "$PSPath" -Name "$Name" -Value "$Value" -PropertyType "$Type" |
| 30 | + } |
| 31 | + else { |
| 32 | + # Name exists and we should set it |
| 33 | + Set-ItemProperty -Path "$PSPath" -Name "$Name" -Value "$Value" -ErrorAction Stop |
| 34 | + } |
| 35 | +} |
0 commit comments