简体   繁体   中英

Remotely query logged in Open Directory users from PowerShell (find if user logged into machine)

I am in a mixed environment with both macOS (OSX) and Windows, dual booting on our client machines. We have an Open Directory and an Active Directory running. macOS connects to OD, Windows to AD.

For all our computers, I wanna know which OS they have currently booted (if any) and if there is a user logged on. This should be done remotely (for example from our AD-Server).

I wrote a script in PowerShell that gets the list of all our machines from the Active Directory and tests if they are currently online (via Test-Connection ). It then tries Get-WMIObject for each machine that is online to test if it is currently booted into Windows and if there is currently a logged on user. If it is online, but Get-WMIObject cannot connect, I assume it is booted into macOS.

The question is: How can I, from PowerShell, find out if a user is currently logged into a certain macOS machine, either by remotely querying the respective machine or our Open Directory?

If it is on a mac you should be able to run the command:

last | grep "logged in"

and it should show you who is there. Since we know this works, we can use Powershell to determine if the computer is on windows or mac with the environment variables now available. If you run this, pointed at the appropriate scripts, it should solve the issue you are seeing.

if ($isOSX) {
    .\callshell.sh
}
elseif ($isWindows) {
    .\callPoSH.ps1
}
else {
  throw "Oh boy this is bad"
}

Let me know if this works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM