简体   繁体   中英

How can i call PowerShell script in php to get the lastlogin data from two Domain Controllers in AD

I'm working in PHP and because of the issue mention below.

Issue: Lastlogon attribute stores the timestamp of the Domain controller through the user is authenticated. For instance, during the authentication, if it uses Domain1 then it will update the timestamp in that Domain controller and vice versa. The same applies when my application fetches the data, and the attribute value in that DC during the authentication will be displayed.

Since we have a primary and secondary DC in our environment for Two types of People, the value of the LastLogon attribute will be different for the same account in each DC based on the DC that is used for authentication and hence it's showing the different LastLogon.

Please find more details here

Solution:

We found a way to write a PowerShell script for getting the lastlogin from both Domain Controllers and publish the latest one after comparing it.

Script was ready and I have no idea how to place and run the code from PHP(Apache server). Any suggestion or step by step procedure will help. Below is the code where lastlogon is placed.

$this->attributes = array("department","whencreated","whenchanged", "pwdlastset","lastlogon","objectsid","homedrive");

You're probably looking for shell_exec().

You'll definitely need perl installed to run a perl script.

Then, in your PHP, you call

$answer = shell_exec( 'yourscriptname.pl' )

or

$answer = shell_exec( 'perl yourscriptname.pl' )

$answer will contain the output of the perl script.

EDIT: Depending on the configuration of your server and the location of the script, you may need to explicitly state the path of the perl executable and the script.

(This example assumes unix/linux)

$answer = shell_exec( '/usr/bin/perl /path/to/yourscriptname.pl' )

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