2017-05-25 16 views
0

私は最近、Powershellで遊んできました。基本コマンドであるnet user $usernameで試してみました。例としてnet user administratorproduces an output that you can see at the bottom of this page.powershellコマンドから特定の情報を出力する方法は?

私の質問は次のとおりです。この特定の要素をどのように出力しますか?

私はパイプについて認識しており、使用しようとしていますが、決して正しく出ないので、何かが欠けていると思います。例えば、user namefull namepassword expireslast logonを出力として表示したいとしましょう。これを得るためにパイプの後にどのコマンドを使用しますか?

多くの感謝!

答えて

0

net.exeは、PowerShellコマンドレットではありません。したがって、情報を取得すると、実行可能ファイルの出力を文字列として処理しています。

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

あなたはWin10 1607以降を使用している場合、あなたは

Get-LocalUser administrator | Select-Object Name,FullName,PasswordExpires,LastLogon 
Get-LocalUserコマンドレットを使用してこの情報を取得できます。ユーザー名を取得する例えば

関連する問題