Last active
August 29, 2015 14:27
-
-
Save AdamNaj/81b63c59e26259953be8 to your computer and use it in GitHub Desktop.
File Download attempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# unfortunately does not work, because - #1 - does not really retrieve the file, #2 has problems with logging out | |
Import-Module -Name SPE | |
function Retrieve-SitecorePackage($session, $instance, $PackageName, $Destination){ | |
$loginUri = "$instance/sitecore/login" | |
$login = Invoke-WebRequest -Uri $loginUri -SessionVariable webSession | |
$form = $login.Forms[0] | |
$form.Fields["__EVENTTARGET"] = "" | |
$form.Fields["UserName"] = $session.Username | |
$form.Fields["Password"] = $session.Password | |
$form.Fields["RememberMe"] = 'on' | |
$loggedInResponse = Invoke-WebRequest -Uri $loginUri -WebSession $webSession -Method POST -Body $form.Fields | |
$args = @{ | |
PackageName = $PackageName | |
} | |
$webSession = Get-SessionCookie $session $instance | |
$handle = Invoke-RemoteScript -Session $session -ArgumentList $args -ScriptBlock { | |
[Sitecore.Web.FileHandle]::GetFileHandle("$($SitecoreDataFolder)packages\$($params.PackageName)") | |
} | |
$url = "$instance/sitecore/shell/download.aspx?file=$handle" | |
Invoke-WebRequest $url -OutFile $Destination -WebSession $webSession | |
$form = $login.Forms[0] | |
$form.Fields["__RequestVerificationToken"] = $webSession.Cookies.GetCookies($url)["__RequestVerificationToken"].ToString() | |
Invoke-WebRequest "$instance/api/sitecore/Authentication/Logout?sc_database=master" -WebSession $webSession -Method POST -Body $form.Fields | |
} | |
$instance = "http://sitecore8" | |
$session = New-ScriptSession -Username admin -Password b -ConnectionUri $instance | |
$packageName = "Sitecore PowerShell Extensions-3.2 for Sitecore 8.zip" | |
Retrieve-SitecorePackage $session $instance $packageName "C:\Users\Adam\Downloads\$packageName" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment