Blog Image

PowerShell

SharePoint Powershell Commands

GoSharePoint Website
Documentation Blog

This blog is based on SharePoint 2013 PowerShell Commands. Please visit my other blog which contains SharePoint Documentation.

Configure People Picker

Administration Posted on Tue, June 28, 2016 07:03:20

Set-ExecutionPolicy -ExecutionPolicy “Unrestricted” -Force

Write-Host “”

Write-Host “========================================================”

Write-Host “People Picker – Adding Trusts……”

Write-Host “- Set an encryption key for use with a one-way trust ”

Write-Host “- Enable cross-forest or cross-domain queries when you use a one-way trust”

Write-Host “- Set an encryption key for use with a one-way trust ”

Write-Host “- Set an encryption key for use with a one-way trust ”

Write-Host “https://technet.microsoft.com/en-gb/library/gg602075.aspx”

Write-Host “========================================================”

Write-Host “”

$URLList = @()

$URLList += “http://spsite”

$URLList += “http://spsite:<Central Admin Port>”

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

try

{

Write-Host “- Updating encryption key”

stsadm -o setapppassword -password <passphase>

foreach ($URL in $URLList)

{

Write-Host “- Enable cross-forest or cross-domain queries for” $URL

STSADM -o setproperty -pn peoplepicker-searchadforests -pv “domain:<ad.domain.com,AD\xxx_SP_Profile,<service account password>;forest:ad.forestdomain.com,AD\xxx_SP_Profile,<service account password>” -url $URL

}

}

catch { Write-Output $_ }



Create Alternate Access Mappings

Administration Posted on Tue, June 28, 2016 06:57:25

#Examples of Alternate Access Mappings
#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

#create the public URL

New-SPAlternateURL -URL “http://spsite” -Zone “Default” -WebApplication “SharePoint – 80” -ErrorAction SilentlyContinue

New-SPAlternateURL -URL “https://spsite” -Zone “Intranet” -WebApplication “SharePoint – 80” -ErrorAction SilentlyContinue

New-SPAlternateURL -URL “https://bi.spsite.com” -Zone “Internet” -WebApplication “SharePoint – 80” -ErrorAction SilentlyContinue

New-SPAlternateURL -URL “https://spsite” -Zone “Default” -WebApplication “SharePoint – 80” -ErrorAction SilentlyContinue

New-SPAlternateURL -URL “http://spsite.com” -Zone “Intranet” -WebApplication “SharePoint – 80” -ErrorAction SilentlyContinue



Set the super user account utilized by the cache

Administration Posted on Tue, June 28, 2016 05:05:02

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

$w = Get-SPWebApplication “http://sprootsite/”

$w.Properties[“portalsuperuseraccount”] = “i:0#.w|AD\xxx_SP_Farm”

$w.Properties[“portalsuperreaderaccount”] = “i:0#.w|AD\xxx_SP_Farm”

$w.Update()



Get Expired Users from List

Administration Posted on Tue, June 28, 2016 01:44:17

Import-Module ActiveDirectory

function FileTime2Date($time) {

return ([datetime]::FromFileTime($time)).DateTime

}

$today = Get-Date

$userlist = Get-Content “C:\temp\GetExpiredUsersfromList.txt”

Get-ADUser -Filter * -Properties * |

select sAMAccountName, accountExpirationDate, @{n=’passwordExpiry’;

e={FileTime2Date $_.’msDS-UserPasswordExpiryTimeComputed’}} |

? { $userlist -contains $_.sAMAccountName -and (

$_.accountExpirationDate -le $today -or

$_.passwordExpiry -le $today

)

}



Checks whether the script is running as admin

Administration Posted on Tue, June 28, 2016 01:42:48

# ===================================================================================

#Checks whether the script is running as admin, if not then starts as admin.

# ===================================================================================

If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”))

{

$arguments = “& ‘” + $myinvocation.mycommand.definition + “‘”

Start-Process powershell -Verb runAs -ArgumentList $arguments

Break

}