Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help getting script to function #21

Closed
dilpatel45 opened this issue Feb 23, 2019 · 9 comments
Closed

Help getting script to function #21

dilpatel45 opened this issue Feb 23, 2019 · 9 comments

Comments

@dilpatel45
Copy link

Hello everyone, I am have difficulties getting the script to generate any output. This is what im trying
Get-Asset -url "https://name.org" -apikey "keystringinhere" | Where-Object {$_.name -eq "nameofdevice" }

The output shows nothing.

@snazy2000
Copy link
Owner

If your run it without the where-object does it return anything?

@dilpatel45
Copy link
Author

I've tried without the where-object and I get this error message:
At line:1 char:1135

  • ... WM2Il0qU6hCHDn3Gpt7szK7ziQfgYv-WI_rVXLSX2gIFk" | {$_.name -eq "MIS" }
  •                                                  ~~~~~~~~~~~~~~~~~~~~
    

Expressions are only allowed as the first element of a pipeline.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline

I ran the whole command with verbose and this is what i get:

VERBOSE: [ConvertTo-GetParameter] Making HTTP get parameter string out of a hashtable
VERBOSE: [Invoke-SnipeitMethod] Invoking method Get to URI
https://snipe.maderacoe.org/api/v1/hardware?offset=0&sort=created_at&limit=50&order=desc
VERBOSE: GET https://snipe.maderacoe.org/api/v1/hardware?offset=0&sort=created_at&limit=50&order=desc with 0-byte
payload
VERBOSE: [Invoke-SnipeitMethod] Failed to get an answer from the server
VERBOSE: [Invoke-SnipeitMethod] No Web result object was returned from. This is unusual!
VERBOSE: [Invoke-SnipeitMethod] Function ended

@snazy2000
Copy link
Owner

The log suggests it cannot connect to the server

@dilpatel45
Copy link
Author

That's strange, i've tried the IP address and hostname and I get the same error message. I've also turned off the firewall on Snipe-IT server. I'm missing something. Any suggestions?

@snazy2000
Copy link
Owner

@dilpatel45 are you still having issues with this? if so can you try running

Get-Asset -url "https://name.org" -apikey "keystringinhere" -verbose

@dilpatel45
Copy link
Author

@snazy2000 yes, i'm still having issues. Is there something in snipe I need to change or alter or verify?

PS C:\Windows\system32> Get-Asset -url "https://snipe.domain.org" -apikey "KEY(actual key)" -verbose

VERBOSE: [ConvertTo-GetParameter] Making HTTP get parameter string out of a hashtable
VERBOSE: [Invoke-SnipeitMethod] Invoking method Get to URI
https://snipe.maderacoe.org/api/v1/hardware?offset=0&sort=created_at&limit=50&order=desc
VERBOSE: GET https://snipe.maderacoe.org/api/v1/hardware?offset=0&sort=created_at&limit=50&order=desc with 0-byte
payload
VERBOSE: [Invoke-SnipeitMethod] Failed to get an answer from the server
VERBOSE: [Invoke-SnipeitMethod] No Web result object was returned from. This is unusual!
VERBOSE: [Invoke-SnipeitMethod] Function ended
PS C:\Windows\system32>

@snazy2000
Copy link
Owner

Can you access the url from the machine your running the script? Do you have anything on your network that blocks powershell making requests like your AV or firewall.

Is the key 100% correct? May be worth trying to access it via application like postman to make sure you can access the API etc

@dilpatel45
Copy link
Author

Yes, I've verified i can resolve the hostname. I've even tried turning off the firewall internally for testing. Same issue. Yes, i've generated the key multiple times but same error message. I'll check with postman and update again.

@dilpatel45
Copy link
Author

dilpatel45 commented May 13, 2019

Got it working now, thanks. I was using a Self-Signed certificate to access snipe. I found this command online to bypass and allow self-signed certificates:

if (-not("dummy" -as [type])) {
    add-type -TypeDefinition @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

public static class Dummy {
    public static bool ReturnTrue(object sender,
        X509Certificate certificate,
        X509Chain chain,
        SslPolicyErrors sslPolicyErrors) { return true; }
    public static RemoteCertificateValidationCallback GetDelegate() {
        return new RemoteCertificateValidationCallback(Dummy.ReturnTrue);
    }
}
"@
}

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [dummy]::GetDelegate()

Source: https://stackoverflow.com/questions/36456104/invoke-restmethod-ignore-self-signed-certs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants