This function:
function Get-UserNameSIDfromAD { param( [string] $LoginName ) [string] $domain [string] $username $domain, $username = $LoginName.split('\') $w32usracc = Get-CimInstance -ClassName win32_useraccount -Filter "Name='$username' and Domain='$domain'" | Select-Object -Property SID $res = [pscustomobject] @{ ID = 1 SqlSID = $w32usracc.SID Message = 'OK' } return $res } #Using the function and get the result in variable and show using out-gridview $val = Get-UserNameSIDfromAD -LoginName 'mydomain\user1' $val | out-gridview
Grid shows incorrectly the information, if run the code without function, the grid shows information correctly.
Please any advice, thank in advance.