PHP | Powershell脚本输出数据

标签 php windows powershell formatting

我有一个 powershell 脚本,它在事件目录中搜索给定的用户名并返回有关该用户的属性,以下是脚本:

Param([string]$username)
Import-Module ActiveDirectory
Get-ADUser $username -Properties GivenName, Surname, DisplayName, Enabled, PasswordExpired, Created, LastLogonDate 

如您所见,我已经给了它一个我想要返回的属性列表,并且它成功返回了它。问题是它还返回我不想要的其他内容,例如“DistinguishedName”。看看下面我返回的​​内容:

Created           : 30/07/2014 11:55:39
DisplayName       : Testing Acount
DistinguishedName : CN=Testing Acount,OU=Disscuss,OU=Users,OU=Company,DC=Company,DC=local
Enabled           : True
GivenName         : Testing
LastLogonDate     : 18/08/2014 12:27:40
Name              : Testing Acount
ObjectClass       : user
ObjectGUID        : d135516b-4c10-41f1-9fa5-4f48bcacc891
PasswordExpired   : False
SamAccountName    : testingacount
SID               : S-1-5-21-1161181520-173477490-3285844792-2188
Surname           : Acount
UserPrincipalName : <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aadecfd9dec3c4cdcbc9c5dfc4deeac9c5c7dacbc4d384c6c5c9cbc6" rel="noreferrer noopener nofollow">[email protected]</a>

如何解决这样的问题并使其仅返回我所声明的属性,或者甚至可能在删除不需要的位后对其进行过滤。

最佳答案

只需将 Get-ADUser 命令通过管道传输到 Select-Object:

Get-ADUser $username | Select-Object GivenName, Surname, DisplayName, Enabled, PasswordExpired, Created, LastLogonDate

这应该只会返回您想要的元素。

编辑:Get-ADUser 命令不会返回您想要的所有属性。您需要使用 -Properties 参数,然后将其通过管道传输到 Select-Object

 Get-ADUser $username -Properties GivenName, Surname, DisplayName, Enabled, PasswordExpired, Created, LastLogonDate | Select-Object GivenName, Surname, DisplayName, Enabled, PasswordExpired, Created, LastLogonDate

这是 Get-ADUser 函数的 technet 页面:http://technet.microsoft.com/en-us/library/ee617241.aspx

关于PHP | Powershell脚本输出数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25552716/

相关文章:

javascript - 数组未发送所有元素,仅获取第一个元素

php - 通过 PHP 测试 Comet 服务器功能的测试套件

c# - 使用NAudio C#减少映射扬声器和麦克风音量的延迟

使用 SSL/TLS 安全通道的 Powershell Invoke-WebRequest 失败

parsing - 给定重复的部分,如何使用 Powershell 查找符合特定条件的部分

php - 接口(interface)的现实世界实现

php - 如何在 wp_posts 表中手动插入带有 html 代码的字符串

c++ - DirectX10 交换链和设备指向 0x00000000(导致运行时错误)(c++)

c++ - FSCTL_GET_RETRIEVAL_POINTERS 对小文件失败

c# - 如何在 Windows 窗体应用程序中运行 PowerShell 命令?