Reputation: 293
this is probably really simple... but how do I check which lines of a log/config file contain any of the strings from a string array?
Example of file (I want lines 3 and 5)
[Privilege Rights]
SeSystemtimePrivilege = *S-1-5-19,*S-1-5-21-2262136377-125853592-2400401627-1119,*S-1-5-32-544
SeDenyNetworkLogonRight = Guest
SeCreatePagefilePrivilege = *S-1-5-32-544
SeDenyServiceLogonRight = *S-1-5-21-2262136377-125853592-2400401627-1119
SeRemoteShutdownPrivilege = *S-1-5-32-544
SeAuditPrivilege = *S-1-5-19,*S-1-5-20
Script I am using:
$SeRightsArray = @(
'SeDenyNetworkLogonRight',
'SeDenyBatchLogonRight',
'SeDenyServiceLogonRight',
'SeDenyInteractiveLogonRight',
'SeDenyRemoteInteractiveLogonRight')
$LocalPolicyExport = gc "C:\local-security-policy.inf"
Foreach($Line in $LocalPolicyExport){
if ($Line -match $SeRightsArray ){
write-host "FOUND - $line"
}
}
Normally I would use something like -contains or -in, but that doesn't work
Upvotes: 1
Views: 162
Reputation: 61083
You can use gc "C:\local-security-policy.inf" | select-string $seRightsArray
. No need for a loop
PS C:\> gc .\test.txt|select-string $SeRightsArray
SeDenyNetworkLogonRight = Guest
SeDenyServiceLogonRight = *S-1-5-21-2262136377-125853592-2400401627-1119
Upvotes: 1