SharePoint Saturday STL: SharePoint Powershell Admins

17
1 | SharePoint Saturday St. Louis 2015 SharePoint PowerShell Admins Examples and Tips to make your life easier.

Transcript of SharePoint Saturday STL: SharePoint Powershell Admins

1 | SharePoint Saturday St . Louis 2015

SharePoint PowerShell AdminsExamples and Tips to make your life easier.

2 | SharePoint Saturday St . Louis 20152 | SharePoint Saturday St . Louis 2015

Session Evaluations

Schedule and evaluate each session you attend via our mobile app that can be

used across devices at

http://spsaturday. azurewebsites.net

You will be able to evaluate sessions added to your “My Sessions” 25 minutes

before the scheduled end time

Evaluations are stored anonymously and your feedback is appreciated

The app will be the only method available to submit session evaluations for the

event and we hope you find it intuitive and convenient

2 | SharePoint Saturday St . Louis 2015

3 | SharePoint Saturday St . Louis 20153 | SharePoint Saturday St . Louis 2015

Ken Maglio [email protected]

World Wide Technology, INC.

Lead Application Administrator

SharePoint Experience – 6 years

Developer – 15 years

Admin – 10 years

Instructor – SLU Workforce Center

Twitter: @kenmaglio

Biography

3 | SharePoint Saturday St . Louis 2015

4 | SharePoint Saturday St . Louis 20154 | SharePoint Saturday St . Louis 2015

Outline

6 | S h a r e P o i n t S a t u r d a y S t . L o u i s 2 0 1 5

• General PowerShell Tips and Tricks• Create Functions

• Get-Member

• Write-Host

• Create your own CSVs

• Store Credentials “better”

• Get Current Directory

• Remote PowerShell

• SharePoint PowerShell Scripts• Walkthrough scripts – forget PowerPoint!

Outline

5 | SharePoint Saturday St . Louis 2015

General PowerShellTips and Tricks

6 | SharePoint Saturday St . Louis 20156 | SharePoint Saturday St . Louis 2015

• Create Functions with Parameters!

function My-FunctionName {

param (

[Parameter(ValueFromPipeline)][string]$parameter1,

[Parameter(ValueFromPipeline)][string]$parameter2

)

process {

Write-Host($parameter1)

Write-Host($parameter2)

}

}

My-FunctionName “Ken” “Maglio”

General PowerShell Tips and Tricks

7 | SharePoint Saturday St . Louis 20157 | SharePoint Saturday St . Louis 2015

• Get-Member• This will show all of the Functions (methods) and Properties

of an object or variable.

$myWeb = Get-SPWeb https://sharepoint.company.com

$myWeb | get-member

General PowerShell Tips and Tricks

8 | SharePoint Saturday St . Louis 20158 | SharePoint Saturday St . Louis 2015

• Write-Host • If you’re trying to get exact spacing use:

• e.g. “Some Text: literally goes here.”

$v = “literally”

Write-Host(“Some Text: “ + $v + “ goes here.”)

• You can attempt to utilize:$v = “literally”

Write-Host “this is $v a test”

• This usually works, however inside of commands sometimes it will not to variable replaces.

• However doing something like this does not work:write-host "this is " + $v + " a test"

write-host "this is " $v " a test"

write-host "this is "$v" a test"

• Does work:write-host "this is"$v" a test"

General PowerShell Tips and Tricks

9 | SharePoint Saturday St . Louis 20159 | SharePoint Saturday St . Louis 2015

• Generate your own CSVs$header = “title,url”

$filePath = “C:\file.csv”

$header | Out-File –FilePath $filePath –Force

# get all site collections – excluding mysites

$sc = Get-SPSite –Limit ALL | where {$_.url –notlike “*mysites*”}

$sc | ForEach-Object {

$row = $_.RootWeb.Title

$row += “,”

$row += $_.Url

$row | Out-File –FilePath $filePath -Append

}

PowerShell Tips and Tricks

10 | SharePoint Saturday St . Louis 201510 | SharePoint Saturday St . Louis 2015

• Storing Credentials “better”• Get-Credentials stored with random encryption key

• Able to store credentials “better” then plain text

• Secured password stored as variable

• Key to decrypt also stored as variable

• SecureString can still be broken down to plain-text.

• Example Script

PowerShell Tips and Tricks

11 | SharePoint Saturday St . Louis 201511 | SharePoint Saturday St . Louis 2015

• Get Current Directory

$app = $MyInvocation.MyCommand.Definition

$dir = [System.IO.Path]::GetDirectoryName($app)

PowerShell Tips and Tricks

12 | SharePoint Saturday St . Louis 2015

PowerShellRemoting(CredSSP)

13 | SharePoint Saturday St . Louis 201513 | SharePoint Saturday St . Louis 2015

• Run winrm quickconfig• If we get an error (unknowing security error) it's probably because there is

an SPN on an account or on the machine name - which is using HTTP -they have to be removed, then winrm quickconfig, and re-added if they are needed.

• You will need to run these potentially to ensure roles are enabled correctly:• enable-wsmancredssp -role server

• enable-wsmancredssp -role client -delegatecomputer *.domain.local

• Add trusted hosts on client machines:• winrm set winrm/config/client '@{TrustedHosts="*"}'

• You may want to use something other than * here …

Remote PowerShell

14 | SharePoint Saturday St . Louis 2015

SharePoint PowerShell

15 | SharePoint Saturday St . Louis 201515 | SharePoint Saturday St . Louis 2015

• Scripts we will review:• Create Site Collection and Content DB (1:1)• Get BestBets• Connecting to UPA

• Restore from SQL

• UPA Migrator• Connecting to Managed Metadata Term Store

• Get Used / UnUsed Terms

• Hosts File – cross farm – UNC paths• Modify Web.Config files the RIGHT way

• Enable Blob Cache example

• Reset Cache – cross farm (psremoting)• Farm Reset – cross farm (psremoting)

• Turn on Version for all libraries in Site Collection• Add/Remove users to SP group

SharePoint PowerShell

16 | SharePoint Saturday St . Louis 201516 | SharePoint Saturday St . Louis 2015

Housekeeping

Follow SharePoint Saturday St. Louis on Twitter @spsstlouis and

hashtag #spsstl

Play “Sponsor Bingo” to register for your chance to win one of the

many great giveaways at the end of the day

Schedule and evaluate each session you attend via our mobile app

that can be used across devices at:

http://spsaturday.azurewebsites.net

17 | SharePoint Saturday St . Louis 201517 | SharePoint Saturday St . Louis 2015

Outline

6 | S h a r e P o i n t S a t u r d a y S t . L o u i s 2 0 1 5

Thanks to Our Sponsors!

Gold Silver Raffle