I’ve written a script using the match operator to find the string ‘^net use h: \\’ within logon scripts. This works for the majority of our scripts (batch files) but I’m having trouble with some of them. For example, if the string appears on the first line of the logon script, the result I get for $Path is a Boolean object type when I expect it to be a String. If the string appears on any other line of the script, I get my String object, as expected. I’ve verified this with Get-Member. Can anyone shed some light on this for me? Here’s an extract of my code :
$Users = Get-ADUser -Filter {Enabled -eq $EnabledUsersOnly} -Properties ScriptPath, HomeDirectory -SearchBase $SearchBase foreach ($user in $users) { $Path = $Null $LogonScript = $Null if ($user.ScriptPath) { try{ $LogonScript = Get-Content ("\\MyDomain\netlogon\" + $User.ScriptPath) $Path = $LogonScript -match '^net use h: \\\\' } catch{ Write-Warning "There was an issue accessing the logon script for $($user.name)" } } if ($Path) { try{ $Path = $Path -replace ".*:" , "" $Path = $Path.Trim() } catch{ Write-Warning "Unable to trim path" } }