PowerGUI: Get-SPWeb : Microsoft SharePoint is not supported with version 4.0.30319.1 of the Microsoft .Net Runtime.

Po aktualizaci používá PowerGUI (http://www.powergui.org) standardně .NET Framework 4.0, ten ale není podporován pro práci s SharePointem 2010, podporován je pouze a jen 2.0 (3.5), jinak při práci s API vznikají výjimky:

Get-SPWeb : Microsoft SharePoint is not supported with version 4.0.30319.1 of the Microsoft .Net Runtime.

 

Přímo v nástroji PowerGUI nelze verzi .NET Frameworku změnit, je potřeba upravit konfigurační soubor aplikace:

  1. Otevřít cestu C:\Program Files (x86)\PowerGUI
  2. Najít a otevřít soubor ScriptEditor.exe.config v poznámkovém bloku
  3. Odmazat nebo zakomentovat řádek <supportedRuntime version=“v4.0″ sku=“.NETFramework,Version=v4.0″ />
  4. Po uložení a restartu aplikace se defaultně použije .NET Framework 2.0 (respektive s nástavbou na 3.5)

Zamknutí/odmknutí všech kolekcí webů ve webové aplikace najednou

Vstupní parametry:

  • webAppUrl – URL adresa webové aplikace
  • lockState
    • ReadOnly = zamčení pouze pro čtení
    • Unlock = odemčení zpět pro editaci

 

Příklad:

.\SetLockStateInAllSiteCollections.ps1 -webAppUrl http://srvdev:81/ -lockState ReadOnly

 

<#
   .Synopsis
	Sets/removes all site collection lock in web application
   .Example
   .\SetLockStateInAllSiteCollections.ps1 -webAppUrl http://srvdev:81/ -lockState ReadOnly
   .\SetLockStateInAllSiteCollections.ps1 -webAppUrl http://srvdev:81/ -lockState Unlock
   .Notes
	NAME: SetLockStateInAllSiteCollections.ps1
	AUTHOR: novotny@devit.cz
   .Link
	http://www.devit.cz
#>

param (
	[Parameter(Mandatory=$True)]
    [string]$webAppUrl,
	[Parameter(Mandatory=$True)]
    [string]$lockState
)

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

$webApp = Get-SPWebApplication $webAppUrl
$allSites = $webApp | Get-SPSite

foreach ($site in $allSites)
{
    Write-Host "Setting " -nonewline
    Write-Host $site.url -nonewline
    Write-Host " to $lockState..." -nonewline
    Set-SPSiteAdministration -LockState $lockState -Identity $site.url
    Write-Host "[OK]" -foregroundcolor green
}

SetLockStateInAllSiteCollections.ps1 (952,00 bytes)

Enumerace všech kolekcí webů a vypsání stavu zámku (site collection lock)

Vstupní parametry:

  • nejsou

 

Příklad:

.\CheckSiteCollectionsLock.ps1

 

<#
   .Synopsis
	Enumerate all site collections and write out lock status
   .Example
   .\CheckSiteCollectionsLock.ps1
   .Notes
	NAME: .\CheckSiteCollectionsLock.ps1
	AUTHOR: novotny@devit.cz
   .Link
	http://www.devit.cz
#>

Add-pssnapin Microsoft.SharePoint.Powershell -ErrorAction silentlycontinue

$webApps = Get-SPWebApplication | foreach {
	write-host "Web App: " $_.Url
	
	$sites = $_.Sites | foreach {
		write-host "   $($_.RootWeb.Url) ($($_.RootWeb.Title)): " -foregroundcolor Green -NoNewline
		
		if ($_.ReadOnly -eq $false -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $false) { 
			write-host "Unlocked" -foregroundcolor Green
		}
		else {
			if ($_.ReadOnly -eq $false -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $true) { 
				write-host "Adding Content Prevented" -foregroundcolor Red
			}
		    elseif ($_.ReadOnly -eq $true -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $true) { 
				write-host "Read-only" -foregroundcolor Red
			}
		    elseif ($_.ReadOnly -eq $null -and $_.ReadLocked -eq $null -and $_.WriteLocked -eq $null) { 
				write-host "No Access" -foregroundcolor Red
			}
			
			if ($_.lockissue -ne $null) {
		          write-host "      Message: $($_.LockIssue)" -BackgroundColor Red
			}
		}
	 }
 }

 

CheckSiteCollectionsLock.ps1 (1,27 kb)

Spuštění workflow na všech položkách/dokumentech pomocí PowerShellu

Vstupní parametry:

  • siteUrl – URL adresa na web kde se nachází seznam
  • listTitle – název seznamu
  • workflowName – název workflow (asociace)
  • workflowCulture – v jakém jazyce je název WF (default en-US)
  • restartIfRunning – pokud WF běží, zastaví se (default je NE, vynechá se zpracování)

 

Příklad:

.\StartListWorkflowOnAllItems.ps1 -siteUrl http://srvdev:81/ -listTitle „Documents“ -workflowName „Approval WF“ -restartIfRunning $true

 

StartListWorkflowOnAllItems.ps1 (2,62 kb)

 

<# 
   .Synopsis 
    Start workflow on all items in list or document library
   .Example
   .\StartListWorkflowOnAllItems.ps1 -siteUrl http://srvdev:81/ -listTitle "Documents" -workflowName "Approval WF" -restartIfRunning $true
   .Notes 
    NAME: StartListWorkflowOnAllItems.ps1
    AUTHOR: novotny@devit.cz
   .Link 
    http://www.devit.cz
#> 

param (
    [Parameter(Mandatory=$True)]
    [string]$siteUrl,
    [Parameter(Mandatory=$True)]
    [string]$listTitle,
    [Parameter(Mandatory=$True)]
    [string]$workflowName,
    [string]$workflowNameCulture = "en-US",
    [boolean]$restartIfRunning = $true
)

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 

$web = Get-SPWeb -Identity $siteUrl

Write-Host "Opening site '$($web.Title)'"

$manager = $web.Site.WorkFlowManager

$list = $web.Lists[$listTitle]
if ($list -eq $null) {
    Write-Host "Unable to find list '$listTitle'" -ForegroundColor Red
    return
}
 
$assoc = $list.WorkflowAssociations.GetAssociationByName($workflowName, $workflowNameCulture)
if ($assoc -eq $null) {
    Write-Host "Unable to find WF association '$workflowName' for culture '$workflowNameCulture'" -ForegroundColor Red
    return
}
 
$data = $assoc.AssociationData
$items = $list.Items

Write-Host "Starting workflows in list '$($list.Title)'"
foreach($item in $items)
{
    $itemName = $item.Title
    if ($item.FileSystemObjectType -eq [Microsoft.SharePoint.SPFileSystemObjectType]::File) {
        $itemName = $item.File.Name
    }

    Write-Host "Starting on ID:$($item.ID) - '$itemName'"
    try {
        $runningWf = $null

        foreach($wf in $item.Workflows) {
            if ($wf.AssociationId -eq $assoc.Id -and ($workflow.InternalState -ne 'Completed' -and $workflow.InternalState -ne 'Cancelled')) {
                $runningWf = $wf
                break
            }
        }

        if ($restartIfRunning -eq $false -and $runningWf -ne $null) {
            Write-Host "   Already Running... Skipping" -ForegroundColor Green
            continue
        }

        if ($runningWf -ne $null) {
            Write-Host "   Stopping existing WF" -ForegroundColor Green
            [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($runningWf)
        }
        
        $wf = $manager.StartWorkFlow($item, $assoc, $data, $true)
        Write-Host "   OK" -ForegroundColor Green
    }
    catch [System.Exception] {
        Write-Host "   ERROR:" $_ -ForegroundColor Red
    }
}
  
$manager.Dispose()
$web.Dispose()