Board logo

标题: [转载代码] [PowerShell每日技巧]查看本地组里面有哪些用户(20131220) [打印本页]

作者: DAIC    时间: 2013-12-30 13:15     标题: [PowerShell每日技巧]查看本地组里面有哪些用户(20131220)

In PowerShell, local accounts and groups can be managed in an object-oriented way thanks to .NET Framework 3.51 and above. This will list local administrator accounts:
  1. Add-Type -AssemblyName System.DirectoryServices.AccountManagement
  2. $type = New-Object DirectoryServices.AccountManagement.PrincipalContext('Machine', `
  3. $env:COMPUTERNAME)
  4. $group = [DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($type, `
  5. 'SAMAccountName', 'Administrators')
  6. $group.Members | Select-Object -Property SAMAccountName, LastPasswordSet, LastLogon, Enabled
复制代码
You can get a lot more, though. Try and query the group by itself:
  1. $group
复制代码
Or try and view all properties for all members:
  1. $group.Members
复制代码
http://powershell.com/cs/blogs/tips/archive/2013/12/20/getting-local-group-members.aspx




欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2