This is a snippet of a much larger script. When the user enters a Last name in the field that contains an apostrophe it will not find the user unless they enter 2 apostrophes. How can I remedy this?
function getacctname {
$fname = $FirstName.Text
$lname = $LastName.Text
Try {
$User.Text = Get-ADUser -Filter "GivenName -eq '$fname' -and SurName -eq '$lname'" -Properties physicalDeliveryOfficeName |
Select-Object 'SamAccountName',@{Name='Office';Expression={$_.physicalDeliveryOfficeName}} |
Out-Gridview -Title 'Windows Logon' -PassThru | Select-Object -Expand SAMAccountName
$Email.Text = (Get-ADUser $User.text -Properties mail).mail
}