Power Shell for Add on Local User

param(
[string] $envType = $(throw “envType(PersonalDev, SharedDev, Test, Sandbox or Production)required”),
[string] $workFolder = (Get-Item (“.”)).FullName,
[string] $wspName = “MyTest.My.Intra.wsp”
)

if(-not(Get-PSSnapin | Where { $_.Name -eq “Microsoft.SharePoint.PowerShell”})) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}

$solName = “MyTest.My.Intra.wsp”

function create-account ([string]$accountName = “testuser”) {
$hostname = hostname
$comp = [adsi] “WinNT://$hostname”
$user = $comp.Create(“User”, $accountName)
$user.SetPassword(“Test1234!”)
$user.SetInfo()
}

switch ($envType)
{
“PersonalDev”
{
$comp = Get-WmiObject -Class Win32_ComputerSystem
$hostHeader = “intra.Mydev.local”
$port = 80
$siteUrl = “http://” + $hostHeader
$appPoolName = “SharePoint – ” + $hostHeader + $port
#$solPath = (Get-ChildItem (“..\bin\Debug\” + $wspName)).FullName

}
“SharedDev”
{
$comp = Get-WmiObject -Class Win32_ComputerSystem
$hostHeader = “intra.Mydev.MyTest.com”
$port = 80
$siteUrl = “http://” + $hostHeader
$appPoolName = “SharePoint – ” + $hostHeader + $port
$solPath = $workFolder + “\” + $wspName
}
“Test”
{
$comp = Get-WmiObject -Class Win32_ComputerSystem
$hostHeader = “test-avenue.My.com”
$port = 80
$siteUrl = “http://” + $hostHeader
$appPoolName = “SharePoint – ” + $hostHeader + $port
$solPath = $workFolder + “\” + $wspName
}
“Sandbox”
{
$comp = Get-WmiObject -Class Win32_ComputerSystem
$hostHeader = “playground-avenue.My.com”
$port = 80
$siteUrl = “http://” + $hostHeader
$appPoolName = “SharePoint – ” + $hostHeader + $port
$solPath = $workFolder + “\” + $wspName
}
“Production”
{
$comp = Get-WmiObject -Class Win32_ComputerSystem
$hostHeader = “avenue.My.com”
$port = 80
$siteUrl = “http://” + $hostHeader
$appPoolName = “SharePoint – ” + $hostHeader + $port
$solPath = $workFolder + “\” + $wspName
}
default
{
throw “Error: unknown value given for parameter 1 envType”
}
}

[string] $UserName=””
[string] $UserNameMy=”MyVisitor”
$Counter=21
Write-Host “Creating MyVisitor Users:”
for ($i = 1; $i -lt $Counter; $i++)
{
$UserName= $UserNameMy + $i
Write-Host “$UserName”
create-account $UserName
}

$UserNameMy=”MyContributor”
$Counter=4
Write-Host “Creating MyContributor Users:”
for ($i = 1; $i -lt $Counter; $i++)
{
$UserName= $UserNameMy + $i
Write-Host “$UserName”
create-account $UserName
}

$UserNameMy=”MyAdmin”
$Counter=3
Write-Host “Creating MyAdmin Users:”
for ($i = 1; $i -lt $Counter; $i++)
{
$UserName= $UserNameMy + $i
Write-Host “$UserName”
create-account $UserName
}

Write-Host “Done!”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s