9789b01acd
Claude-Session: https://claude.ai/code/session_01GT67AD5mc2BnaaAfY3hqqQ
35 lines
2.3 KiB
PowerShell
35 lines
2.3 KiB
PowerShell
# Rewrite one service's env block (NSSM AppEnvironmentExtra or SCM Environment): drop entries whose NAME matches
|
|
# $Drop, append $Add. Every other entry stays byte-identical (checked). No restart. Rendered per call.
|
|
$ErrorActionPreference = 'Stop'
|
|
$Svc = 'MxAccessGw'; $Kind = 'nssm' # nssm | svc
|
|
$Drop = '^(MxGateway__Ldap__|MxGateway__Dashboard__GroupToRole__)'
|
|
$Add = @('MxGateway__Ldap__Enabled=true',
|
|
'MxGateway__Ldap__Server=uswap-vdc-nam1.nam.zimmer.com',
|
|
'MxGateway__Ldap__Port=636',
|
|
'MxGateway__Ldap__Transport=Ldaps',
|
|
'MxGateway__Ldap__AllowInsecure=false',
|
|
'MxGateway__Ldap__FallbackServers__0=uswap-vdc-nam2.nam.zimmer.com:636',
|
|
'MxGateway__Ldap__SearchBase=DC=nam,DC=zimmer,DC=com',
|
|
'MxGateway__Ldap__ServiceAccountDn=svc_igntadmin@nam.zimmer.com',
|
|
'MxGateway__Ldap__ServiceAccountPassword=${secret:nam-ldap-svc-password}',
|
|
'MxGateway__Ldap__UserNameAttribute=sAMAccountName',
|
|
'MxGateway__Ldap__DisplayNameAttribute=name',
|
|
'MxGateway__Ldap__GroupAttribute=memberOf',
|
|
'MxGateway__Ldap__BindMode=ServiceAccount',
|
|
'MxGateway__Dashboard__GroupToRole__UG_WW_APP_ADMIN_QA=Administrator',
|
|
'MxGateway__Dashboard__GroupToRole__UG_WW_APP_IDE_QA=Viewer',
|
|
'MxGateway__Dashboard__GroupToRole__UG_WW_APP_IDE_RO_QA=Viewer')
|
|
$k = "HKLM:\SYSTEM\CurrentControlSet\Services\$Svc"
|
|
if ($Kind -eq 'nssm') { $k = "$k\Parameters"; $prop = 'AppEnvironmentExtra' } else { $prop = 'Environment' }
|
|
$before = @((Get-ItemProperty $k -Name $prop).$prop)
|
|
$kept = @($before | Where-Object { $n = $_.Substring(0, [Math]::Max(0,$_.IndexOf('='))); $n -notmatch $Drop })
|
|
$dropped = @($before | Where-Object { $kept -notcontains $_ } | ForEach-Object { $_.Substring(0,$_.IndexOf('=')) })
|
|
foreach ($a in $Add) { $n = $a.Substring(0,$a.IndexOf('=')); if (@($kept | Where-Object { $_ -like "$n=*" }).Count) { throw "add collides with kept entry $n" } }
|
|
$new = $kept + $Add
|
|
Set-ItemProperty -Path $k -Name $prop -Value ([string[]]$new) -Type MultiString
|
|
$after = @((Get-ItemProperty $k -Name $prop).$prop)
|
|
if ($after.Count -ne $new.Count) { throw 'count mismatch after write' }
|
|
for ($i = 0; $i -lt $new.Count; $i++) { if ($after[$i] -cne $new[$i]) { throw "entry $i differs after write" } }
|
|
"$Svc ($prop) $($before.Count) -> $($after.Count) entries; dropped: $($dropped -join ', ')"
|
|
foreach ($a in $Add) { " + $a" }
|