简体   繁体   English

如何在 php 中调用 PowerShell 脚本以从 AD 中的两个域控制器获取上次登录数据

[英]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.我正在使用 PHP 并且因为下面提到的问题。

Issue: Lastlogon attribute stores the timestamp of the Domain controller through the user is authenticated.问题:Lastlogon 属性通过用户进行身份验证存储域控制器的时间戳。 For instance, during the authentication, if it uses Domain1 then it will update the timestamp in that Domain controller and vice versa.例如,在身份验证期间,如果它使用 Domain1,那么它将更新该域控制器中的时间戳,反之亦然。 The same applies when my application fetches the data, and the attribute value in that DC during the authentication will be displayed.这同样适用于我的应用程序获取数据时,将显示身份验证期间该 DC 中的属性值。

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.由于我们的环境中有两个类型的人的主要和次要 DC,因此每个 DC 中的同一帐户的 LastLogon 属性值将根据用于身份验证的 DC 不同,因此它显示不同的 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.我们找到了一种编写 PowerShell 脚本的方法,用于从两个域控制器获取最后一个登录名,并在比较后发布最新的登录名。

Script was ready and I have no idea how to place and run the code from PHP(Apache server).脚本已准备就绪,我不知道如何从 PHP(Apache 服务器)放置和运行代码。 Any suggestion or step by step procedure will help.任何建议或分步程序都会有所帮助。 Below is the code where lastlogon is placed.下面是放置 lastlogon 的代码。

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

You're probably looking for shell_exec().您可能正在寻找 shell_exec()。

You'll definitely need perl installed to run a perl script.您肯定需要安装 perl 才能运行 perl 脚本。

Then, in your PHP, you call然后,在你的 PHP 中,你调用

$answer = shell_exec( 'yourscriptname.pl' )

or或者

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

$answer will contain the output of the perl script. $answer 将包含 perl 脚本的输出。

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.编辑:根据服务器的配置和脚本的位置,您可能需要明确说明 perl 可执行文件和脚本的路径。

(This example assumes unix/linux) (此示例假设为 unix/linux)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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