Hmm...This Might Work

Solutions from a day long since past
posts - 20, comments - 7, trackbacks - 0

Thursday, May 29, 2014

AD User Account Creation–Script

I’m throwing this script out there for any developers or admins who are seeking a quick SharePoint focused script for user account creation.

In my environment we’re working towards automated unattended install of SharePoint, including account creation. AutoSPInstaller is cool
but it seems too complicated for me. Put another way, if I’m going to spend time learning I’m choosing to learn PowerShell and SharePoint
in more detail.

With that said, here is my script. This script could easily import from a CSV (or other file), read a SharePoint List, or any other means of
input. For the purpose of an example, an array is used.

 

#Make Use Of An Array Just for example. This could easily be a csv but since this was for dev it was easier

#In Case of CSV Column Order would be "SamAccountNAme,FName,LName,Description,Password

#$UserList = Import-CSV -Path <csv path here>

$UserList = @(

@("<SamAccountName>","<FName>","<LName>","<Description>","<PassworD>"),

@("<SamAccountName1>","<FName1>","<LName1>","<Description1>","<PassworD1>"),

@("<SamAccountName2>","<FName2>","<LName2>","<Description2>","<PassworD2>")

)

#Loop Through Each Nested Array

ForEach ($User in $UserList) {

$SamAccountName = $User[0]#(Read-Host -Prompt "Please Enter SamAccountName")

#Check To See If SamAccountName Already Exists, If It Doesnt Create It

If (!(Get-ADUser -Filter {SamAccountNAme -eq $SamAccountName})){

    $OUPath = "OU=<OUName>,OU=<OUName>,DC=<DomainRoot>,DC=<dot suffix>"

    $DomainSuffix = "@<domain.org>"

    $FName = $User[1]

    $LName = $User[2]

    $Description = $User[3]

    $PassWord = ConvertTo-SecureString ($User[4]) -AsPlainText -Force #(Read-Host -Prompt "Enter Account Password" -AsSecureString)

    New-ADUser -Name ($FName+" "+$LName) -SamAccountName $SamAccountName -GivenName $FName -Surname $LName -DisplayName ($FName+" "+$LName) -Path $OUPath -UserPrincipalName ($SamAccountName+$domainsuffix) -Description $Description -AccountPassword $PassWord  -PasswordNeverExpires:$true -Enabled:$true

    }

Else

    {

    Write-Host "$SamAccountName already exists within AD. It will not be created"

    }

}

 

posted @ Thursday, May 29, 2014 4:18 PM | Feedback (0) | Filed Under [ SharePoint ActiveDirectory SharePoint 2010 Powershell SharePoint 2013 ]

Disable LoopBack Script - SharePoint

A friend of mine and I were discussing the topic of Disabling LoopBack and which is the better route to go when it comes to creating a new SharePoint 2013 farm.

My perspective, when possible, abide by Microsoft’s recommendations. In this case Microsoft seems to take the classic “it depends” stance on disabling ye old loopback.

Being me, I asked my self why not have both? After all I’m sure PowerShell could help out here. To those who know me or have read this blog; I’m not a developer and

it probably shows in various scripts. That said, the following script does accomplish the desired result of one script allowing you to choose if you are going to take the

“Developer” route and disable the loopback, or take the “Admin” route and call out your exceptions. If you are a new SharePoint Admin this might be useful, if you arent

new to SharePoint then I’m sure you’ve already clicked off of this post a few lines back…lol

#Disable LoopBack Or Enter Back Connection Name

#Use this to avoid disabling loopback - http://support.microsoft.com/kb/896861

#Define in CSV format your FDQNs

$DisableLoopBack = $null

Do {$DisableLoopBack = (Read-Host "Would you like to disable loopback? (Yes / No)") }

Until ($DisableLoopBack -eq "Yes" -or $DisableLoopBack -eq "No")

If ($DisableLoopBack -eq "Yes"){

Write-Warning "According To Microsoft You Should NOT disable loopback, HOWEVER it's a common development practice."

New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword -Force | Out-Null

IISReset /noforce

}

Elseif ($DisableLoopBack -eq "No"){

$HostNames = @()

$HostNames+=($env:COMPUTERNAME+"."+$env:USERDNSDOMAIN)

$More = $null

Do {

Write-Host "Here are the host names that will be added to the BackConnectionHostNames Exception List"

Write-Host $HostNames -ForegroundColor Green

$More = (Read-Host "Would you like to add others? (Yes / No)")

If ($More -eq "Yes"){

$AddHost = (Read-Host "Enter FQDN Host Name")

$HostNames+=$AddHost

Write-Host "$AddHost has been added to the list of names above" -ForegroundColor Green

$More = (Read-Host "Would you like to add others? (Yes / No)")

}

}

Until ($More -eq "No")

New-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0 -Name "BackConnectionHostNames" -Value $HostNames -PropertyType MultiString

IISReset /noforce

}

posted @ Thursday, May 29, 2014 4:05 PM | Feedback (0) | Filed Under [ SharePoint 2010 Powershell SharePoint 2013 ]

Powered by: