#SharePoint 2013 #PowerShell: How to get user permissions report

function Get-SPPermissionsReport($web, $recursive)
  $web | Get-SPUser | % { New-Object PSObject -Property @{
    UserLogin = $_.UserLogin
    'Roles given explicitly' = $_.Roles
    'Roles given via groups' = $_.Groups | %{$_.Roles}
    Groups = $_.Groups
    Url = $web.Url
  if($recursive) { $web.Webs | % { Get-SPPermissionsReport $_ $recursive } }
$web = Get-SPWeb http://yoursharepoint/sites/department
Get-SPPermissionsReport $web $true | Sort-Object UserLogin | Out-GridView

Then you can apply an additional filter by user or url right in the GridView.
You can add an additional matching criteria in the GridView: e.g. match by Role/Group name

PowerShell; SharePoint 2010: Set Alternate Access Mapping

I need to set Alternate Access Mapping remotely as part of my automation. I can’t find how to specify PowerShell version for Invoke-Command CMDlet. So I decided to use this workaround:

Invoke-Command -computer sp2010.vlasenko.org -script {
  $command = "Add-PSSnapin Microsoft.SharePoint.PowerShell; New-SPAlternateURL 'http://vlasenko.nmsp.org' -Zone 'Internet' -WebApplication 'SharePoint - 80'"
  PowerShell -v 2 -Command "& { $command }"

Bind SharePoint event receiver by PowerShell

$list = (get-spweb http://sharepoint/sites/test).lists['somelist']
$def = $list.EventReceivers.Add()
$def.Assembly = "MyReceiverAssembly, Version=, Culture=Neutral,PublicKeyToken=a00000000a000ce0"
$def.Class = "MyReceiverAssembly.MyReceiverClass"
$def.Type = [Microsoft.SharePoint.SPEventReceiverType]::ItemAdded
$def.Name = "My ItemAdded Event Receiver";
$def.Synchronization = [Microsoft.SharePoint.SPEventReceiverSynchronization]::Synchronous

#PowerShell #SCOM Preserve/Update Created By/Modified By

This example shows how to use SharePoint Client Object API through PowerShell to create a list item with specific Author and Editor.
Useful if you want to preserve identities while moving the SharePoint items.

$siteUrl = "http://mysite"
$listTitle = "My List"
$user = "9;#domain\user"

cd "$installFolder"
Add-Type -Path .<PATH>\Microsoft.SharePoint.Client.dll
$ctx = new-object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$web = $ctx.Web
$list = $web.Lists.GetByTitle($listTitle)

$itemInfo = new-object Microsoft.SharePoint.Client.ListItemCreationInformation
$item = $list.AddItem($itemInfo)
$item['Title'] = "Hello World"
$item['Author'] = $user
$item['Editor'] = $user

The tricky part here is the $user value. It should be in the form of: {user Id in SharePoint};#{user Name}
You can automate the process of getting the user Id number by Name.