Power shell命令返回不正确的用户名格式 [英] Power shell commands returning the improper user name format

查看:120
本文介绍了Power shell命令返回不正确的用户名格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(get-wmiobject Win32_ComputerSystem -ComputerName< user pc =name =>)。UserName 

返回用户名格式低于

< systemname> /< domainname> /< username> 

以上用户名格式将在我登录时获取使用Microsoft凭据。



当我使用本地帐户登录到PC时,返回以下用户名格式的相同命令

< domainname> /< username> 

当我登录时,为什么它会返回

< systemname> /< domainname> /< username> 

Windows 8.1中的microsoft帐户?



我尝试过:



i尝试拆分命令以获得正确的用户名格式。

解决方案

这是正常的。无论WMI返回什么,Powershell都会返回。 WMI返回完全限定的domain\username。如果你只想要用户名,你将不得不解析该字符串或将其拆分为\字符,并在拆分后返回字符串。



你可以这样做:

(get-wmiobject Win32_ComputerSystem).UserName.Split('\')[1] 


(get-wmiobject Win32_ComputerSystem –ComputerName "<user pc="" name="">").UserName

is returning the user name in the below format

<systemname>/<domainname>/<username>

The above User name format will get when i logged in with Microsoft credentials.

When i logged in with Local account to PC, the same command returning the below Username Format

<domainname>/<username>

Why it is returning

<systemname>/<domainname>/<username>

when i Logged in with microsoft account in Windows 8.1?

What I have tried:

i have tried splitting the commands to get proper username format.

解决方案

That's normal. Powershell is returning whatever WMI is returning. WMI returns the fully qualified "domain\username". If you want just the user name, you're going to have to parse that string or split it on the "\" character and just return the string after the split.

You can do that like this:

(get-wmiobject Win32_ComputerSystem).UserName.Split('\')[1]


这篇关于Power shell命令返回不正确的用户名格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆