samedi 26 septembre 2020

read the value from registry rather than hard code in if statement

i have below powershell line. It will return 1 when there is account found in administrators group other than built-in administrator, group1, group2, group3.

If ((Get-LocalGroupMember -Group Administrators | Where-Object {($_.ObjectClass -eq 'User' -or $_.ObjectClass -eq 'Group') -and (($_.Name -notlike "$env:computername\administrator") -and ($_.Name -notlike 'group1')  -and ($_.Name -notlike 'group2')  -and ($_.Name -notlike 'group3') )}).Count -gt 0) {
echo 1
}else{
echo 0
}

how do i change the above if statement to read in the string value (which has commas) in registry so I don’t need to hard code group1, group2, group3 in the if statement?? Thanks

example i had set it at hklm:\system\test , named as adm and string value of group1,group2,group3

i am able to pull the value i set at registry using this line.

$listofadm = (Get-ItemProperty -Path "HKLM:\system\test" -ErrorAction Stop -Name adm).adm

Aucun commentaire:

Enregistrer un commentaire