Skip to content

Instantly share code, notes, and snippets.

@leojplin
Created December 2, 2018 18:08
Show Gist options
  • Save leojplin/1ee63362860275ec2ddf54620ffa6b66 to your computer and use it in GitHub Desktop.
Save leojplin/1ee63362860275ec2ddf54620ffa6b66 to your computer and use it in GitHub Desktop.
function Add-ToProject {
[CmdletBinding()]
param (
[Parameter(ValueFromPipelineByPropertyName=$True)]
[String]
$ServerName,
[Parameter(ValueFromPipelineByPropertyName)]
[String]
$ProjectPath,
[Parameter(ValueFromPipelineByPropertyName)]
[String]
$PagePath
)
begin {
}
process {
$server = $aemEnv | Where-Object -Property name -Value $ServerName -eq
if($server -eq $null){
Write-Error -Message "ServerName $ServerName is not found."
return;
}
$pair = "$($server.user):$($server.password)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$url = $server.host
$basicAuthValue = "Basic $encodedCreds"
$headers = @{
Authorization = $basicAuthValue;
"Content-Type"="application/x-www-form-urlencoded";
"User-Agent"="curling"
}
$form = @{
":translationJobPath"="$ProjectPath/jcr:content/dashboard/gadgets/translationjob"
"_charset_"= "UTF-8"
"createLanguageCopy"= "false"
":operation"= "ADD_TRANSLATION_PAGES"
"translationpage"= $PagePath
}
try{
$res = Invoke-WebRequest -Uri "$($url)$ProjectPath/jcr:content/dashboard/gadgets/translationjob" -Method Post -Headers $headers -Body $form
$res.StatusCode
Write-Information "$PagePath added to project $ProjectPath."
Write-Output $ProjectPath
}catch{
# throw $_.Exception
Write-Error -Message "$PagePath failed to add to project $ProjectPath"
return
}
}
end {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment