Common Tasks

Add PSSnapin

 # check to ensure Microsoft.SharePoint.PowerShell is loaded
    $snapin=Get-PSSnapin | Where-Object {
       $_.Name -eq 'Microsoft.SharePoint.Powershell'}
       if ($snapin -eq $null) {
       Write-Host "Loading SharePoint Powershell Snapin"
       Add-PSSnapin "Microsoft.SharePoint.Powershell"
       }

Start/Stop Admin Service

function CheckAdminService
{
    if ($(Get-Service $adminServiceName).Status -eq 'Stopped')
    {
        $isAdminServiceWasRunning = $false;
        Start-Service $adminServiceName
        #Write-Host ''
        Write-Host 'SERVICE WAS STOPPED, SO IT IS NOW STARTED'
    }
}

function StopAdminService
{
    if (-not $isAdminServiceWasRunning)
    {
        Stop-Service $adminServiceName
        Write-Host 'SERVICE HAS BEEN STOPPED'
    }
}

Start/Stop Global Assignment

Start-SPAssignment -Global    # This cmdlet takes care of the disposable objects to prevent memory leak.

Stop-SPAssignment -Global

 

New DEV machine deployment setup

New DEV machine setup - Sharepoint 2010 is already installed

  1. Add your account to Web Application Group
  2. If your account is not recognized, install people picker
  3. Verify term store access

Enable running Powershell scripts on your computer

Run this command from PS console:

 

Set-ExecutionPolicy RemoteSigned

 

details

Run powershell script from cmd line

C:\Documents and Settings\Lukas\My Documents\P_R_O_G_R_A_MOVANIE\powerShell>powershell .\praram_switch.ps1

Run batch file from powershell cmd line

PS C:\Documents and Settings\Lukas\Desktop\XMLskusky> .\OpenFiles.bat

Group features by Scope, where syntax

Get-SPFeature|sort -property DisplayName | FT -GroupBy Scope DisplayName ID

 

#display Desktop item - basic columns

get-childitem|where { $_.name  -eq "Desktop"}

#display all items - basic columns
write-host ""
get-childitem

 

#display all items - names only in one row
write-host ""
$item=get-childitem
write-host $item

 

#display all items only name
write-host ""
foreach($item in get-childitem)
    {
        write-host $item.name

    }

 

#sorts items according to Mode
write-host ""
get-childitem|sort -property Mode
 

Mark all errors terminating

$ErrorActionPreference="Stop"

Check for directory exists

if (Test-Path C:\Export){
  write "it exists!"
}

1 | 2 >>