#获取当前登录用户用户名 $curuser = (Get-WmiObject Win32_ComputerSystem).UserName #根据当前登录用户用户名获取用户SID $ob = New-Object System.Security.Principal.NTAccount(“$curuser”) $sid = $ob.Translate([System.Security.Principal.SecurityIdentifier]) $sid.Value...
$objUser = New-Object System.Security.Principal.NTAccount($env:UserName) $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]).Value $strSID 运行这个命令后,将显示当前用户的 SID。 PowerShell 命令来获取当前计算机上所有会话的信息: powershellCopy Code Get-WmiObject Win32_LogonSe...
whoami /user:这个命令可以显示当前登录用户的SID、域、登录名等信息。 wmic useraccount get name,sid:这个WMIC(Windows Management Instrumentation Command-line)命令可以列出所有用户账户的名称和SID。 使用Windows API: Windows API提供了函数来查询用户信息,包括LookupAccountName,它可以根据用户名查找SID,或者LookupAccoun...
This approach has onelimitationwhich is you can only get the SID of either alocal userora domain user who has logged inat least once onto this machine. 3. WMIC There is this approach which we can use and will work in all of the cases except on any OS pri...
Get-LocalUser [[-Name] <String[]>] [<CommonParameters>]PowerShell 复制 Get-LocalUser [[-SID] <SecurityIdentifier[]>] [<CommonParameters>]说明Get-LocalUser cmdlet 获取本地用户帐户。 此 cmdlet 获取默认的内置用户帐户、你创建的本地用户帐户以及连接到 Microsoft 帐户的本地帐户。备注 Microsoft.Powe...
#1.获取当前登录用户;$CurrentLogonUser=(Get-WMIObject-query"SELECT * FROM win32_Process WHERE Name ='explorer.exe'"|Foreach{$owner=$_.GetOwner();$_|Add-Member-MemberType"Noteproperty"-name"Owner"-value$owner.User-passthru}).Owner|select-object-first 1#2.获取当前用户的SID;$user=New-Object...
Get-WinEvent 参考 反馈 模块: Microsoft.PowerShell.Diagnostics 获取本地和远程计算机上的事件日志和事件跟踪日志文件中的事件。 语法 PowerShell复制 Get-WinEvent[[-LogName] <String[]>] [-MaxEvents <Int64>] [-ComputerName <String>] [-Credential <PSCredential>] [-FilterXPath <String>] [-Force] [...
Get-LocalUser 这将列出所有本地用户的详细信息,包括用户名、描述、SID等。 接下来,我们可以使用以下命令来设置用户的密码过期策略: 代码语言:txt 复制 Set-LocalUser -Name "用户名" -PasswordNeverExpires:$false 这将禁用用户的密码永不过期选项,强制用户在下次登录时更改密码。
下面介绍用PowerShell查询指定OU中所有账号的创建时间\SID\上次修改密码时间\最后一次登录时间,CMDlet如下: Get-ADuser -searchbase 'OU=User,OU=Compay1,DC=Domain,DC=COM' -filter * -Properties * | Select-Object Name,SID, Created,PasswordLastSet,@{n="lastLogonDate";e={[datetime]::FromFileTime($...
__MethodProviderRegistration {} {provider} __PropertyProviderRegistration {} {provider, SupportsGet, SupportsPut} __EventConsumerProviderRegistration {} {ConsumerClassNames, provider} __NAMESPACE {} {Name} __EventFilter {} {CreatorSID, EventAccess, EventNamespace, Name...} __EventConsumer {} {...