Presentation is loading. Please wait.

Presentation is loading. Please wait.

SharePoint Bruger Gruppe  Vi skal snakke om  Status på SPBG  Ny struktur på vores ERFA møder  Andre møder  Dagens emne: PowerShell.

Similar presentations


Presentation on theme: "SharePoint Bruger Gruppe  Vi skal snakke om  Status på SPBG  Ny struktur på vores ERFA møder  Andre møder  Dagens emne: PowerShell."— Presentation transcript:

1

2 SharePoint Bruger Gruppe  Vi skal snakke om  Status på SPBG  Ny struktur på vores ERFA møder  Andre møder  Dagens emne: PowerShell i SharePoint 2010

3 SharePoint Bruger Gruppe  Praktisk information  Lokaler, sodavand og sandwich bliver sponseret af Enabling Danmark  Lokaler  Vi mangler sponsorer til lokaler til vores ERFA møder

4 SharePoint Bruger Gruppe  Mere diskussion!

5 SharePoint Bruger Gruppe  PowerShell i SharePoint 2010 af Per Jakobsen

6 SharePoint Bruger Gruppe  SharePoint dinner inden jul, følg med på og twitter.

7 SharePoint Bruger Gruppe

8  Introduction to Powershell  PowerShell and SharePoint 2010  Custom Cmdlet  PowerShell and SharePoint 2007  Actions Per Jakobsen

9 SharePoint Bruger Gruppe  chdircdSet-Location  lsdirGet-ChildItem  cpcopyCopy-Item  erasedelRemove-Item  mkdirNew-Item –type directory  cattypeGet-Content

10 SharePoint Bruger Gruppe  Aliases  History (History, r, F7, F8)  Tab completion (incl. wildcard)  Piping (|)  Redirecting (>, >>, 2>, 2>>, 2>&1)  Tee

11 SharePoint Bruger Gruppe  grep (Select-String)  Immediate expressions  2+2  “Hello ” + “World”  Beware type of left side wins  2 + “2”  “2” + 2  2 + “test”

12 SharePoint Bruger Gruppe  Virtual drives C:, D:,…Disk drives ENV:Environment variables HKLM:, HKCU:Registry Variable:Variables …  Get-PSDrive

13 SharePoint Bruger Gruppe  Objects as long as possible Get-Process | Where-Object {$_.Handles –lt 500} | Sort-Object CPU –desc | Select-Object –first 5

14 SharePoint Bruger Gruppe  Output formatting  Format-Table  Format-Table –auto  Format-List

15 SharePoint Bruger Gruppe  Prefixed by $  Untyped by default, but can be typed $a = 1 $a = “test” [int]$a = 1 $a = “test”  Error $a = “2”  OK, converted to int

16 SharePoint Bruger Gruppe  Default scope when setting:  At command lineGlobal  In scriptScript  In functionLocal  When reading first defined of Local, script, global  Can be specified: $global:a = 42

17 SharePoint Bruger Gruppe One Variable to rule them all, One Variable to find them all, One Variable to bring them all and in darkness bind them $_ | Where-Object {$_%2 –eq 1} | ForEach-Object {$_*$_}

18 SharePoint Bruger Gruppe  " text " – expands:  $var  Content of variable  $(expr)  Value of expression  ` used as escape character (NOT \)  ' Text ' – not expanding " > to > - here text

19 SharePoint Bruger Gruppe  1  Int32 / Int64  0x10  Int32/ Int64 (hexadecimal)  1.1  Double  1kb  * by 1024  1mb  * by 1024*1024  1gb  * by 1024*1024*1024

20 SharePoint Bruger Gruppe  1,2,3  Array   Array (Range)  Wraps in array if not already array  HashTable  [System.Enviroment] => Type  Use :: to access static methods/properties  {code}  ScriptBlock (delegate)

21 SharePoint Bruger Gruppe Function sqr($x) { $x*$x; } Sqr 4 Sqr(5)

22 SharePoint Bruger Gruppe Filter odd { if ($_ % 2 –eq 1) { $_ } | odd

23 SharePoint Bruger Gruppe Function test($x) { begin {“B:Param $x”} process {“P:Param $x value $_”} end {“E:Param $x”} } 1..10|test(42)

24 SharePoint Bruger Gruppe  Everything in PowerShell is “just”.Net  Tab completion through reflection $d = [System.DateTime]::Now $d.AddDays(42)

25 SharePoint Bruger Gruppe  Just casting a xml string to [xml] gives you a nice XmlDocument $sols = [xml](stsadm –o enumsolutions) $sols.Solutions.Solution[0] $sols.Solutions.Solution | Where-Object {$_.Name –like “*stsadm*”}

26 SharePoint Bruger Gruppe  Secure out of the box  Scripts (.ps1) are mapped to NotePad  Current directory not in path (use.\xxx)  By default doesn’t allow scripts  Change to allow local scripts: Set-ExecutionPolicy RemoteSigned

27 SharePoint Bruger Gruppe  Enable-PSRemoting (once + restart)  Interactive  Background Enter-PSSession computer –Credential usr $s = New-PSSession computer –Credential usr Invoke-Command $s { cmds } … Remove-Session $s

28 SharePoint Bruger Gruppe Get-Help Get-Help > Get-Help about_* Get-Command –noun sp* $a | Get-Members [System.Math] | Get-Members -static

29 SharePoint Bruger Gruppe

30  PowerShell knows nothing about SP2010  But “SP2010 Management Shell” does  Or  Add-SPShellAdmin (once) Add-PSSnapIn Microsoft.SharePoint.Powershell

31 SharePoint Bruger Gruppe New-SPSite url –OwnerAlias usr –Template XXX Get-SPSite url Remove-SPSite url Remove-SPSite url –confirm:$false New-SPWeb url –Template XXX Get-SPWeb url Get-SPSite url | Get-SPWeb Remove-SPWeb url

32 SharePoint Bruger Gruppe Get-SPWeb url | Select –Expand Lists | Select –Expand Items | Select Name, Url (Get-SPWeb url).RecycleBin

33 SharePoint Bruger Gruppe Get-SPLogEvent –StartTime time –EndTime time | Where-Object {$_.Correlation –eq “guid” } | Select Message

34 SharePoint Bruger Gruppe $web = Get-SPWeb url $web.Title $web.Title = “Title from PS” $web.Update()

35 SharePoint Bruger Gruppe Start-SPAssigment -global $web = Get-SPWeb url … Stop-SPAssignment -global $gc = Start-SPAssigment $web = $gc | Get-SPWeb url … Stop-SPAssignment $gc

36 SharePoint Bruger Gruppe

37  Add Reference:  System.Management.Automation.dll  Microsoft.SharePoint.Powershell.dll  Inherit from SPXXXCmdletBase  Add Attributes  Cmdlet  SPCmdlet  Add xml files in SPRoot\Config\PowerShell

38 SharePoint Bruger Gruppe  PowerShell knows nothing about SP2007  But you can load the dll(s)  Then you can just use the object model [System.Reflection.Assembly]::LoadWithPartial Name(“Microsoft.SharePoint”)

39 SharePoint Bruger Gruppe $site = [Microsoft.SharePoint.SPSite] (“http://localhost”) $web = $site.OpenWeb() $web $web.Title $web.Title = “Updated from PS” $web.Update() $web.Dispose() $site.Dispose()

40 SharePoint Bruger Gruppe  To use PJA’s startup script do this once Set-ExecutionPolicy RemoteSigned If (!(Test-Path $profile)){New-Item –type file –force $profile} Notepad $profile >. $profile

41 SharePoint Bruger Gruppe function Get-SPSite($url) { [Microsoft.SharePoint.SPSite]($url); } # Setting up environment # # Set up path for visual studio tools # function VsVars32() { $vs100comntools = (Get-ChildItem env:VS100COMNTOOLS).Value $batchFile = [System.IO.Path]::Combine($vs100comntools, "vsvars32.bat") $cmd = "`"$batchfile`" & PATH" Set-Content env:\Path (cmd /c $cmd)[1].Split("=")[1] } VsVars32 # Setup path to SharePoint tools # New-Variable 12Hive "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12" -option constant Set-Content Env:\Path ((Get-Content Env:\Path)+";$12Hive\bin;c:\windows\system32\inetsrv") # Load SharePoint Assembly # [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

42 SharePoint Bruger Gruppe  Use Get-Help  Use Get-Command  Use Get-Member Get Started

43 SharePoint Bruger Gruppe  SharePoint dinner inden jul, følg med på og twitter.


Download ppt "SharePoint Bruger Gruppe  Vi skal snakke om  Status på SPBG  Ny struktur på vores ERFA møder  Andre møder  Dagens emne: PowerShell."

Similar presentations


Ads by Google