I have the following PnP PowerShell script:
$conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=$DBServer;Integrated Security=True;Initial Catalog=$DBName")
$conn.Open();
$query = $Query
$dap = new-object System.Data.SqlClient.SqlDataAdapter($query,$conn);
$dt = new-object System.Data.DataTable;
$null = $dap.Fill($dt)
foreach($r in $dt.Rows ) {
$SPUserEmail = $r["email_address"];
$SPuser = (Get-PnPUser | ? Email -eq ($SPUserEmail));}
but I always get this error:
The specified user could not be found.
but if I type the email address manually I get the user details:
$SPuser = (Get-PnPUser | ? Email -eq [email protected]);
although when I do Write-Host $SPUserEmail
I will get [email protected]
So what could be the reason?
$SPUserEmail
holding string/text value? Can you try running script after removing( )
around$SPUserEmail
? Let me know if this works for you.()
did not change any thing