Unexpected token Write-Output

Rising Flight 5,216 Reputation points
2024-02-03T05:30:02.2433333+00:00

Hi All i want to fetch user name or group name from the SID. i am getting the below error when i try to execute the syntax in onprem AD. how can i get this information from Azure AD as well as i have few groups directly created in Azure AD

$secidentifier = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-21-7151733594-696023681-915538951-9220120173") 
$username = $secidentifier.Translate([System.Security.Principal.NTAccount]).Value Write-Output $username


At line:2 char:69
+ ... slate([System.Security.Principal.NTAccount]).Value Write-Output $username
+                                                       ~~~~~~~~~~~~
Unexpected token 'Write-Output' in expression or statement.
    + CategoryInfo         : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 36,291 Reputation points
    2024-02-03T13:41:19.1133333+00:00

    You have 2 PS statements on one line and you have not separated them with the ";" character.

    Put the write-output on a new line.

    $secidentifier = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-21-7151733594-696023681-915538951-9220120173") 
    $username = $secidentifier.Translate([System.Security.Principal.NTAccount]).Value 
    Write-Output $username 
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.