Home > ADDM > Updated ADDM query using Powershell.

Updated ADDM query using Powershell.

This has been updated to allow qu9ick access to ADDM views for people who live in their Powershell Shells.

So a quick – “get-addm myserver – launch” opens the URL – I have not found a way to post the credsa to the logon page yet – as I do not want to depends on simulated keypresses.

</pre>
 
Function get-Addm ($addmserver="MyAddmServer.mydomain.local", $hostname, [string]$query="SEARCH Host WHERE name MATCHES '(?i)$hostname'", $username, $password, $proxy="myproxy:8080", [switch]$resetpwd, [switch]$launch)
 {
 # Use system reflection to convert string to URL.
 [System.Reflection.Assembly]::LoadWithPartialName("System.Web") | out-null
 $query = [System.Web.HttpUtility]::UrlEncode($query)
 
 # Check for password / gather password info
 If ($resetpwd)
  {del $env:userprofile\$username.txt}
 If (!$username)
  {
  write-host "No Username specified - using $env:username" -fore Green
  $username = $env:username
  }
 if (test-path $env:userprofile\$username.txt)
  {
  write-host "Stored creds found for $username" -fore Green
  }
  else
  {
  write-host "No Password saved for $username - please specify a valid pwd" -fore Green
  read-host -assecurestring | convertfrom-securestring | out-file $env:userprofile\$username.txt
  }
  $password = get-content $env:userprofile\$username.txt | convertto-securestring
  $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$password

 # Decrypt stored creds
 $pw =  $credentials.GetNetworkCredential().password
 
 # Create Web request
 $proxy = new-object System.Net.WebProxy $proxy
 # $proxy.credentials = $proxycred.GetNetworkCredential()
 
 $WebClient = New-Object System.Net.WebClient
 $webclient.proxy = $proxy
 $url = "<a href="https://$addmserver/ui/api/CsvApi?query=$query&username=$username&password=$pw">https://$addmserver/ui/api/CsvApi?query=$query&username=$username&password=$pw</a>"
 $Webclient.DownloadFile($url, "$env:temp\tmp.csv")
  #Import captured CSV
 $csv = import-csv "$env:temp\tmp.csv"
 If ($launch){ie "<a href="https://$addmserver/ui/NodeSearch?query=SEARCH%20Host%20WHERE%20name%20MATCHES%20%27%28%3Fi%29$Hostname%27">https://$addmserver/ui/NodeSearch?query=SEARCH%20Host%20WHERE%20name%20MATCHES%20%27%28%3Fi%29$Hostname%27</a>"}
  return $csv
 }
 
 
<pre>

Categories: ADDM Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.