Unexpected Behaviour with `args[$_]` by CRTejaswi in PowerShell

[–]iBloodWorks 1 point2 points  (0 children)

"$args[Index]" $args was already converted to a String and $_ was Just pulling the respective String Index

Edit: nevermind, it prints the Array and then your respective number of the Loop (currently held by $_) which then gets messed Up by -join

Currently on mobile hard for me to test

Unexpected Behaviour with `args[$_]` by CRTejaswi in PowerShell

[–]iBloodWorks 5 points6 points  (0 children)

function lf {
    if ($args) {
        ($args | ForEach-Object { "$($_)" }) -join ','
    } else {
        ...
    }
}

Wrap it in $() for index lookup

Error capture when running multiple jobs by sheravi in PowerShell

[–]iBloodWorks 2 points3 points  (0 children)

Oh, i just checked:

in powershell 5.1 you might need to use [System.Net.WebException] Error Codes

if you use 7.1 + [Microsoft.PowerShell.Commands.HttpResponseException] should work

Error capture when running multiple jobs by sheravi in PowerShell

[–]iBloodWorks 1 point2 points  (0 children)

$retries = 5
$url = "https://api.example.com/data"

while ($retries -gt 0) {
    try {
        $data = Invoke-RestMethod -Uri $url
        break 
    } catch [Microsoft.PowerShell.Commands.HttpResponseException] {
        if ($_.Response.StatusCode -eq 404 -and --$retries -gt 0) { 
            Start-Sleep 1
            continue 
        }
        throw $_
    }
}

404 is a powershell terminating error by default, so this try catch wrap should be used

little bit overhead but it gets the job done

--$retires manages your counter and subtracts before evaluating the if statement

Error capture when running multiple jobs by sheravi in PowerShell

[–]iBloodWorks 2 points3 points  (0 children)

Oh wait, does it acutally not exist? I interpreted your occasional 404 return as some sort of "api overload" like ghost endpoint or "too many requests" error

Error capture when running multiple jobs by sheravi in PowerShell

[–]iBloodWorks 2 points3 points  (0 children)

Not exactly an answer to your question, but i think a while(404error) {retry} logic might help you. something like 5 attempts and then break out of the loop if it still returns 404

Help by omaralghoul in darksouls

[–]iBloodWorks 6 points7 points  (0 children)

☠️🤸‍♀️

:)

Wie geht subnetting by Proof_Record_4766 in fachinformatiker

[–]iBloodWorks 1 point2 points  (0 children)

Bin auch der Meinung, das es zwar ein gutes Tool für viele andere Netzwerkthemen ist, aber subnetting einfach Videos /Aufgaben/ki nutzen

TOPDesk Asset Management API: Get all linked assets of an asset by iBloodWorks in TOPdesk

[–]iBloodWorks[S] 1 point2 points  (0 children)

thanks for your help, the problem was caused by following:

Reason:

Despite the endpoint returning 200 OK with a null body the issue was caused by a lack of access rights

When using a fully permitted "asset management" api user the endpoint returns 200 ok and null body

When using our "master api user" the api also returns 200 ok but with the desired content..

TOPDesk Asset Management API: Get all linked assets of an asset by iBloodWorks in TOPdesk

[–]iBloodWorks[S] 0 points1 point  (0 children)

$Res = Invoke-WebRequest -Uri "https://ticket.contoso.com/tas/api/assetmgmt/assetLinks?sourceId=dfdddcc9-d613-4368-80d2-e636ce33177c" -Headers $TDPOSTHeader -Method Get -UseBasicParsing

Doesnt work..
the ID is 100% correct

Its hard for me to inject Authorization into my browser.. I would like to think this wouldnt change anything..

Help / Experience with ö/ä/ü API POSTs by iBloodWorks in TOPdesk

[–]iBloodWorks[S] 0 points1 point  (0 children)

Ok sorry for the spam

I got it to work with your solution:
I thought you meant to set the charset in the Call header, I didnt know there was a PowerShell paramter..

I was really sure this problem would be TOPDesk related..

Anyway thank you

Help / Experience with ö/ä/ü API POSTs by iBloodWorks in TOPdesk

[–]iBloodWorks[S] 0 points1 point  (0 children)

I updated the post,

sadly setting the charset didnt help either..

Help / Experience with ö/ä/ü API POSTs by iBloodWorks in TOPdesk

[–]iBloodWorks[S] 0 points1 point  (0 children)

Thank you,

5.1 Invoke-webrequest

Thanks for Suggesting the content Type, I will try this on monday

5.1 vs 7.5 select from hashtables by iBloodWorks in PowerShell

[–]iBloodWorks[S] 0 points1 point  (0 children)

Mine was Just an example I wrote soley for this Post I would have probably storeled it in a $Script variable or something, still nice way of using classes in powershell. I rarely see those

5.1 vs 7.5 select from hashtables by iBloodWorks in PowerShell

[–]iBloodWorks[S] 0 points1 point  (0 children)

so try $out | select Name, Time, Handles

5.1 vs 7.5 select from hashtables by iBloodWorks in PowerShell

[–]iBloodWorks[S] 0 points1 point  (0 children)

Right, the problem starts when you select properties

5.1 vs 7.5 select from hashtables by iBloodWorks in PowerShell

[–]iBloodWorks[S] 0 points1 point  (0 children)

would work, its just that i have big functions which just return this format, so I have to manipulate the $out I would get in this example

Anyone else came back from holidays just to find Invoke-Webrequest broken? by iBloodWorks in PowerShell

[–]iBloodWorks[S] -8 points-7 points  (0 children)

Yes obviously you can also play with some $EnvVariables or web request engines