Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Created January 22, 2016 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/6fe7eb24e75c1e1c61fd to your computer and use it in GitHub Desktop.
Save michaellwest/6fe7eb24e75c1e1c61fd to your computer and use it in GitHub Desktop.
Demo code used in the LASUG used in this Google Hangout: https://plus.google.com/events/cdagvle072duivnn0ms7td9h8t4
#region Setup
# The module should reside in $env:PSModulePath
Import-Module -Name SPE -Force
# Use Get-Help to see examples
$props = @{
Session = (New-ScriptSession -Username "admin" -Password "b" -ConnectionUri "http://console")
Verbose = $true
}
#endregion
#region Download File
# Download single file - requires fileDownload patch
Receive-RemoteItem @props -Path "license.xml" -RootPath Data -Destination "C:\temp"
# Download single file - requires mediaDownload patch
Receive-RemoteItem @props -Path "{04DAD0FD-DB66-4070-881F-17264CA257E1}" -Database master -Destination "C:\temp"
#endregion
#region Upload File
# Upload single file - requires fileUpload patch
Get-Item -Path C:\temp\data.xml | Send-RemoteItem @props -RootPath App
# Verify in path C:\inetpub\wwwroot\Console\Website
# Upload single file - requires mediaUpload patch
Get-Item -Path C:\image.png | Send-RemoteItem @props -RootPath Media -Destination "Images/"
# Verify in path /sitecore/media library/Images
#endregion
#region Run Commands
# Run command remotely and return deserialized object
Invoke-RemoteScript @props -ScriptBlock {
Get-User -Id admin
}
$job = Invoke-RemoteScript @props -ScriptBlock {
# Do some long running process
# Install-Package .....
Start-Sleep -Seconds 5
} -AsJob
Wait-RemoteScriptSession @props -Id $job
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment