search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
How to join Windows user to Windows group with Powershell?
Posted in Hosting & IIS7, Windows Powershell, Windows Server | No Comment | 2,983 views | 23/06/2009 10:45

You can join Windows user to Windows group from Powershell:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Add IIS User to IIS Group
function add_user_to_iis_group($username)
	{
		$computergroup = [ADSI]("WinNT://localhost,computer")
		$admins = $computergroup.psbase.children.find("IIS_IUSRS")
		foreach ($member in $admins.psbase.Invoke("Members"))
			{
				$member_name = $member.GetType().InvokeMember("Name", ‘GetProperty’, $null, $member, $null)
				if ($member_name -eq $username) 
					{
						Write-Host $username "already in this group."
						return
					}
			}
		$admins.Add("WinNT://$username")
		Write-Host $username "added to group."
	}
 
add_user_to_iis_group "$username"

It checks user and if it is not exist in that group, add that username.



Leave a Reply