2017-05-25 127 views
0

所以我最近一直在玩Powershell,尝试一些基本命令net user $username。作为一个例子net user administratorproduces an output that you can see at the bottom of this page.如何从powershell命令输出特定信息?

我的问题是:如何输出此特定元素?

我知道管道,一直在尝试使用它们,但我想我错过了一些东西,因为它从来没有出现过。比方说,我只想user name,full name,password expireslast logon作为输出显示。我在管道后使用了什么命令来获得这个命令?

非常感谢!

回答

0

net.exe不是PowerShell cmdlet。因此,获取信息将以字符串的形式处理可执行文件的输出。

例如,检索用户名:如果您使用的是Win10 1607或更高版本,你可以检索与Get-LocalUser cmdlet的

Get-LocalUser administrator | Select-Object Name,FullName,PasswordExpires,LastLogon 
此信息

$netoutput = net user administrator 
#User name is on the first line, separated by spaces, the actual username is last word 
$netoutput[1].Split(" ")[-1]