Trying to get output of dsregcmd /status
Hi
I want to run a script or custom inventory rule, or something that would be able to get the output of dsregcmd /status on the machines, but when I try to set it as a script, it doesn't seem like it is able to run for some reason, and also as a custom inventory rule, it seems it was not able to get any output either.
Has anyone here ever tried this? And how were you able to get the output?
Answers (3)
Hi. Use Powershell and pipe the output to Select-String cmdlet.
Simple example (run within powershell):
dsregcmd /status | Select-String -Pattern "IsUserAzureAd"
If you pack it into foreach statement with list of machines and sprinkle desired output titles in text file after -Pattern, than you might just end up with what you need. Next you could put the output into variables, append each iteration to csv file and generate a nice report in Excel to get the managers attention for a few seconds :)
I am having the same issue and it will not display the information. This is my output from .\KDeploy.exe -custominventory
[2024-06-13.14:55:57][KDeploy:KLaunchClient::DumpState] Launch State: Command="cmd.exe /c "dsregcmd /status | Select-String -Pattern "IsUserAzureAd"" WorkingDir="" Timeout=3600000 ShouldDetach=0 ShowWindow=0 Redirect_stdout=1 Redirect_stderr=0 Desktop=winsta0\default Using Wait_Override=0
[2024-06-13.14:55:57][KDeploy:KLaunchUtils::DoesTokenH] DoesTokenHaveLSAPriviledges returning: 0
[2024-06-13.14:55:57][KDeploy:KLaunchClientImpl::Launc] KLaunchClientImpl::Launch() DoesCurrentProcessHaveLSAPriviledges = false
[2024-06-13.14:55:57][KDeploy:KLaunchClientImpl::Launc] KLaunchClientImpl::LaunchNoSession()
[2024-06-13.14:55:57][KDeploy:KLaunchClientImpl::Setup] KLaunchClientImpl::SetupStartInfo *Don't CreateStdPipe StdIn Pipe (disabled)
[2024-06-13.14:55:57][KDeploy:KLaunchUtils::BuildComma] BuildCommandPath: Did not find cmd.exe /c "dsregcmd /status | Select-String -Pattern "IsUserAzureAd" under searchPath='C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\AdoptOpenJDK\jre-8.0.252.09-hotspot\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;
[2024-06-13.14:55:57][KDeploy:KLaunchClientImpl::Launc] KLaunchClientImpl::LaunchNoSession - CreateProcess returned successfully
[2024-06-13.14:55:57][KDeploy:KLaunchClientImpl::ReadS] KLaunchClientImpl::ReadStdPipe End of ReadStdPipe method
[2024-06-13.14:55:57][KDeploy:KLaunchClientImpl::Wait ] KLaunchClientImpl::Wait WaitForSingleObject failed: status 0, ExitCode 1
[2024-06-13.14:55:57][KDeploy:KLaunchClientImpl::Proce] KLaunchClientImpl::ProcessResults - End
[2024-06-13.14:55:57][KDeploy:CDeployController::Execu] rule [34210] statement result: "", FALSE
[2024-06-13.14:55:57][KDeploy:CDeployController::RunCu] KDeploy finished processing 7 custominventory rules, sending response
[2024-06-13.14:55:57][KDeploy:CDeployController::RunCu] KDeploy sending response: [;1233:Q049TFQtNDc0MCx
Has anyone found a way to get this information?
create a bat within a Script
@echo off
dsregcmd /status>c:\mypath\dsregcmdoutput.txt
exit
create a custom inventory field in INVENTORY > SOFTWARE with the following in the "Custom Inventory Rule:"
ShellCommandTextReturn(cmd /c if exist c:\mypath\dsregcmdoutput.txt type c:\mypath\dsregcmdoutput.txt)
After running the script/bat on a test group, force an inventory on the group. Check the Custom Inventory details under each machine details.