Author Posts

February 28, 2018 at 6:56 am

Hi team,

Any suggestion on how to convert the output of dsregcmd /status into an object? Or, any PowerShell alternative to find if a machine has joined AzureAd or not.

I am getting an output something like this:

PS C:\> dsregcmd /status

| Device State |

AzureAdJoined : YES
EnterpriseJoined : NO

I have to further put an if condition using AzureAdJoined : YES parameter, but I am not able to select it, as it is not a property.
Any help on filtering or formatting?


February 28, 2018 at 7:40 am

If you have only the "strings" from the command you have to parse it by yourself. As far as I know there is no built in magic what transforms this to a Powershell object. So catch the text and use regex to cut it into suitable pieces.

February 28, 2018 at 4:38 pm

Look at ConvertFrom-String as a possible solution

February 28, 2018 at 9:01 pm


I made a little a function with help from the link that Jon posted. Thanks for the link, was a good read.

function Get-DSregcmdstatus {
    $status = dsregcmd /status 
    $status -replace ':', ' ' | 
        Select-Object -Index 5, 6, 7, 13, 14, 15, 16, 17, 18, 19, 25, 26, 27, 28, 29, 30, 31 | 
        ForEach-Object {$_.Trim() }  | 
        ConvertFrom-String -PropertyNames 'State', 'Status'

March 1, 2018 at 1:29 am

Check it out! I had to do 3 examples.

$template = @'
        AzureAdJoined : {AzureAdJoined*:YES}
     EnterpriseJoined : {EnterpriseJoined:NO}
        AzureAdJoined : {AzureAdJoined*:NO}
     EnterpriseJoined : {EnterpriseJoined:YES}
        AzureAdJoined : {AzureAdJoined*:NO}
     EnterpriseJoined : {EnterpriseJoined:NO}

PS C:\> dsregcmd /status | ConvertFrom-String -TemplateContent $template

AzureAdJoined EnterpriseJoined
------------- ----------------
NO            NO

March 1, 2018 at 6:45 am

Thanks Richard, that helped. One question, when I used the code:

dsregcmd /status | ConvertFrom-String | where P2 -eq 'AzureAdJoined'

It's generating properties as P1, P2, P3 and P4. Just wanted to understand if they are random or consistent so that I can hard-code it to my script?

March 1, 2018 at 6:50 am

Thanks Anders, That was help. I found another solution to it meanwhile :). I know it's not a formatting solution, however it worked for a temporary break-fix.

$status = dsregcmd /status | Select-String -Pattern "AzureAdJoined"

    if ($status -match "AzureAdJoined : YES")
            [System.Windows.MessageBox]::Show('Your computer is already a member of AzureAd...') 

March 1, 2018 at 6:53 am

Thanks Jon, It was a good read. Got multiple solutions for one scenario now.. 🙂

March 1, 2018 at 6:54 am

Great JS, thanks a lot. I can see multiple solutions now... Happiest I am... 🙂