I know this is a very old post, but 1. how did you get the rest call to work with invoke-restmethod from powershell? or 2. how do you communicate with foreman via a cli in powershell?
I have hammer cli and hammer cli foreman installed but not sure how to access this from powershell? Thank you, I have tried following the hammer cli docs and various others but not grasping it. THank you very much On Thursday, February 5, 2015 at 11:04:53 PM UTC-6, Corey Osman wrote: > Why mess with curl? You can install the hammer_cli and foreman_hammer_cli > to communicate with foreman via a cli in powershell. > > Its pretty badass and no need to work with curl. > > Corey > > On Tuesday, January 13, 2015 at 11:02:37 AM UTC-8, Schorschi Decker wrote: >> >> Ok, this is really kicking me in the backside... I can't seem to get a >> Foreman REST API query to work from PowerShell? Here is the query I am >> trying to do: >> >> # curl --user admin:password -H "Content-Type:application/json" -H >> "Accept:application/json" -k https://foreman/api/v2/hosts >> >> Here is the PowerShell script: >> >> #[System.Net.ServicePointManager]::ServerCertificateValidationCallback = >> {$true} >> >> add-type @" >> using System.Net; >> using System.Security.Cryptography.X509Certificates; >> >> public class TrustAllCertsPolicy : ICertificatePolicy { >> public bool CheckValidationResult( >> ServicePoint srvPoint, X509Certificate certificate, >> WebRequest request, int certificateProblem) { >> return true; >> } >> } >> "@ >> >> [System.Net.ServicePointManager]::CertificatePolicy = New-Object >> TrustAllCertsPolicy >> >> $dictionary=@{} >> $username = "root" >> $password = "password" >> $uri = "https://foreman/api/v2/hosts" >> $dictionary = New-Object >> "System.Collections.Generic.Dictionary[[String],[String]]" >> #$base64AuthInfo = >> [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f >> $username,$password))) >> $base64AuthInfo = >> [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(("{0}:{1}" -f >> $username,$password))) >> $dictionary.Add("Authorization","$base64AuthInfo") >> $dictionary.Add("Accept","application/json") >> Invoke-RestMethod -Uri $uri -Headers $dictionary -ContentType >> "application/json" -Method GET -Verbose >> #Invoke-WebRequest -Uri $uri -Headers $dictionary -ContentType >> "application/json" -Method GET -Verbose >> >> Invoke-RestMethod and Invoke-WebRequest both fail with the same error... >> >> VERBOSE: GET https://foreman/api/v2/hosts with 0-byte payload >> >> Invoke-RestMethod : The underlying connection was closed: An unexpected >> error occurred on a send.At line:38 char:1 >> + Invoke-RestMethod -Uri $uri -Headers $dictionary -ContentType >> "application/json" ... >> + >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> + CategoryInfo : InvalidOperation: >> (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException >> + FullyQualifiedErrorId : >> WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand >> >> Any help appreciated! >> > -- You received this message because you are subscribed to the Google Groups "Foreman users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/foreman-users. For more options, visit https://groups.google.com/d/optout.
