Powershell枚举远程机器上的本地权限组

前端之家收集整理的这篇文章主要介绍了Powershell枚举远程机器上的本地权限组前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

# ==============================================================================================
# 
# NAME: Get-LocalGroupMembers
# 
# AUTHOR: Ben Baird
# DATE  : 8/12/2011
# 
# COMMENT: 
# Given a machine name,retrieves a list of members in
# the specified group.
# ==============================================================================================

function Get-LocalGroupMembers
{
	param(
		[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
		[Alias("Name")]
		[string]$ComputerName,[string]$GroupName = "Administrators"
	)
	
	begin {}
	
	process
	{
		# If the account name of the computer object was passed in,it will
		# end with a $. Get rid of it so it doesn't screw up the WMI query.
		$ComputerName = $ComputerName.Replace("`$",'')

		# Initialize an array to hold the results of our query.
		$arr = @()

		$wmi = Get-WmiObject -ComputerName $ComputerName -Query `
			"SELECT * FROM Win32_GroupUser WHERE GroupComponent=`"Win32_Group.Domain='$ComputerName',Name='$GroupName'`""

		# Parse out the username from each result and append it to the array.
		if ($wmi -ne $null)
		{
			foreach ($item in $wmi)
			{
				$arr += ($item.PartComponent.Substring($item.PartComponent.IndexOf(',') + 1).Replace('Name=','').Replace("`"",''))
			}
		}

		$hash = @{ComputerName=$ComputerName;Members=$arr}
		return $hash
	}
	
	end{}
}

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的Shell相关文章