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 |
±---------------------------------------------------------------------+
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?
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.
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...')
}
else
{