File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66# Blog: https://blakedrumm.com/
77
88# You can modify the below to use HTTP or HTTPS. Replace <WebConsoleAddress> with the address for your Web Console.
9- $MainURL = ' http://MS02-2022.contoso-2022.com /OperationsManager'
9+ $MainURL = ' http://<WebConsoleAddress> /OperationsManager'
1010
1111function Authenticate-SCOMAPI
1212{
@@ -21,17 +21,19 @@ function Authenticate-SCOMAPI
2121 $EncodedText = [Convert ]::ToBase64String($Bytes )
2222 $JSONBody = $EncodedText | ConvertTo-Json
2323
24+ # Initiate the Cross-Site Request Forgery (CSRF) token, this is to prevent CSRF attacks
25+ $CSRFtoken = $WebSession.Cookies.GetCookies ($MainURL ) | ? { $_.Name -eq ' SCOM-CSRF-TOKEN' }
26+ $SCOMHeaders.Add (' SCOM-CSRF-TOKEN' , [System.Web.HttpUtility ]::UrlDecode($CSRFtoken.Value ))
27+
2428 # Authentication
2529 if ($Credential -ne $null ) {
2630 Invoke-RestMethod - Method Post - Uri " $MainURL /authenticate" - Headers $SCOMHeaders - Body $JSONBody - Credential $Credential - SessionVariable WebSession
2731 } else {
2832 Invoke-RestMethod - Method Post - Uri " $MainURL /authenticate" - Headers $SCOMHeaders - Body $JSONBody - UseDefaultCredentials - SessionVariable WebSession
2933 }
3034 $script :WebSession = $WebSession
31- # Initiate the Cross-Site Request Forgery (CSRF) token, this is to prevent CSRF attacks
32- $CSRFtoken = $WebSession.Cookies.GetCookies ($MainURL ) | ? { $_.Name -eq ' SCOM-CSRF-TOKEN' }
33- $SCOMHeaders.Add (' SCOM-CSRF-TOKEN' , [System.Web.HttpUtility ]::UrlDecode($CSRFtoken.Value ))
3435}
36+
3537Authenticate- SCOMAPI
3638
3739# Function to fetch all installed SCOM Consoles
You can’t perform that action at this time.
0 commit comments