Skip to content

Instantly share code, notes, and snippets.

@petrsvihlik
Last active August 2, 2016 12:21
Show Gist options
  • Save petrsvihlik/204515a87a14217bd3c2a2b991814d40 to your computer and use it in GitHub Desktop.
Save petrsvihlik/204515a87a14217bd3c2a2b991814d40 to your computer and use it in GitHub Desktop.
Using Kentico REST API in PowerShell
$url = "http://localhost/kentico/rest/CMS.User/administrator"
# Enter correct username:password
$credentialsBytes = [System.Text.Encoding]::UTF8.GetBytes("administrator:")
$credentialsEncoded = [System.Convert]::ToBase64String($credentialsBytes)
$headers = @{}
$headers.Add("Authorization", "Basic $($credentialsEncoded)")
# Change requested mime/type
#$headers.Add("Content-Type", "application/json")
# Add -OutFile c:\file.xml if you want to save the output to a file
$xml = (Invoke-RestMethod -Uri $url -Method "Get" -Headers $headers)
# Print user
#$xml.SelectNodes('//CMS_User')
# Update user
$xml.data.CMS_User.UserNickName = "Jack"
# Update user using PUT method
$result = (Invoke-RestMethod -Uri $url -Method "Put" -Headers $headers -Body $xml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment