Skip to content

Instantly share code, notes, and snippets.

@plehr
Created March 7, 2024 09:10
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 plehr/12ef24c1470b31e0d7c18c9c6ab29504 to your computer and use it in GitHub Desktop.
Save plehr/12ef24c1470b31e0d7c18c9c6ab29504 to your computer and use it in GitHub Desktop.
Matrix code collection
# Script for label change on BULK
# Pascal Lehr (CRW058969)
# Config
# Get Session information from chrome. Dev-Tools -> Network -> Filter for change request -> Right click -> Powershell -> Grab session information :)
$url = 610
$newLabel = "MXP"
$AspApp = "3jViaT2h-6Rv7-rAwKAGGnzR-6Rqr9wo3xm9tnVNc6yeCFslKajaNVWeZlECwMb-Zc6vzgf8rW9XPJYrycdGSNXB54MdLqkw_DethgMD8p_4W20o2zI"
$AspMatrixAdmin = "o9CNzob_QHC0pPC2YXKj6HqCbmkVfMSNflqSLa88I7YdOJuCmoo05O26LE2OIYmfu6824qwV1M2MzEIZwcz6ygb2LjEYzQ6LPrXs8BlhiXpX06cYcRqWesqOovbgzaNhzwaYVPIjH2L4vzBweiuy-aVq9XMiXLnFDhECOyqTzy5kXLX00VewrOYhq7f1ImyMJjWoEjHi1PDid8ZR9M1iIjW5-jOcZdIkOcNYhWMFKW8IPTzEHBP6ALh--c2lFJDB04POqx0M-3-JUq31k3UCnxOKl4Atv4aLTF4hp8E1dtwp02HD30bxTH8genrY8swOI3UrZnlc7s_0qw5huIhZ_h6Zx8wh6bKhGLfsJ-xOWjTtYGe9QMLZfibA28F7Km0pbQhYTOHdZ-wxgY9KyIujHMXI8DFfOG3qfLA9hasTK4hOAXog8kwmAOqdDApxVpWOeQ_29zAOBqhvrtfKQTzGA5wLUbLf1vlcFgvY6pKI"
$RequestVer = "4lKW9OTX7TjYLeIqumWANa1J5uHxEQk626j7qJhvivc-MuZo1"
$RequestVerToken = "__RequestVerificationToken_L2lu0"
$AspSess = "3xd3fd1enay52j"
# Nuber of first device .. Number of last device
66..158 | % {
# Do not change below
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$session.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
$session.Cookies.Add((New-Object System.Net.Cookie("sb_admin_culture", "en", "/", "silverback$($url).m42cloud.com")))
$session.Cookies.Add((New-Object System.Net.Cookie("ASP.NET_SessionId", "$($AspSess)", "/", "silverback$($url).m42cloud.com")))
$session.Cookies.Add((New-Object System.Net.Cookie("$($RequestVerToken)", "$($RequestVer)", "/", "silverback$($url).m42cloud.com")))
$session.Cookies.Add((New-Object System.Net.Cookie(".AspNet.Application", "$($AspApp)", "/", "silverback$($url).m42cloud.com")))
$session.Cookies.Add((New-Object System.Net.Cookie(".AspNet.Matrix42Admin", "$($AspMatrixAdmin)", "/", "silverback$($url).m42cloud.com")))
Invoke-WebRequest -UseBasicParsing -Uri "https://silverback$($url).m42cloud.com/admin/Devices/SaveDeviceLabel" `
-Method "POST" `
-WebSession $session `
-Headers @{
"authority"="silverback$($url).m42cloud.com"
"method"="POST"
"path"="/admin/Devices/SaveDeviceLabel"
"scheme"="https"
"accept"="application/json, text/javascript, */*; q=0.01"
"accept-encoding"="gzip, deflate, br, zstd"
"accept-language"="de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"
"cache-control"="no-cache"
"dnt"="1"
"origin"="https://silverback$($url).m42cloud.com"
"referer"="https://silverback$($url).m42cloud.com/admin/Devices/Managed"
"sec-ch-ua"="`"Chromium`";v=`"122`", `"Not(A:Brand`";v=`"24`", `"Google Chrome`";v=`"122`""
"sec-ch-ua-mobile"="?0"
"sec-ch-ua-platform"="`"Windows`""
"sec-fetch-dest"="empty"
"sec-fetch-mode"="cors"
"sec-fetch-site"="same-origin"
"x-requested-with"="XMLHttpRequest"
} `
-ContentType "application/x-www-form-urlencoded; charset=UTF-8" `
-Body "DeviceId=$_&Label=$($newLabel)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment