I run this code and only returning the first 100 records, not sure why.
Can you please advise?
I belive this is what I should modify but don't know how:
$select=displayName,userPrincipalName,signInActivity
This is the full code:
Invoke-WebRequest -Headers $AuthHeader1 -Uri "https://graph.microsoft.com/beta/users?`$select=displayName,userPrincipalName,signInActivity" -UseBasicParsing
Update:
$LastLogin = Invoke-WebRequest -Headers $AuthHeader1 -Uri "https://graph.microsoft.com/beta/users?`$top=999&$select=displayName,userPrincipalName,signInActivity&$skiptoken=Paged=TRUE&$odata.nextlink" -UseBasicParsing
$NextLink = $LastLogin."#odata.nextLink"
$LastLoginpage2 = Invoke-WebRequest -Method Get -Headers $AuthHeader1 -Uri '$NextLink' -UseBasicParsing
Thanks.
Gabor
By default every API has its own limit per page to give number of records as a response. Here the /users gives 100 users per page and additionally it gives a #odata.nextLink as a reference to the next page as shown below in the image.
You can use the odata.nextLink and make another call and get the next page of users.
If you want to modify the limit per page, you can use $top query parameter to get 200 or 300 user objects per page. Use the below query to get 200 records per page.
GET https://graph.microsoft.com/v1.0/users?$top=200&$select=displayName,userPrincipalName,signInActivity
Related
So it is my fist time working with BambooHR and I have basic knowledge on using Powershell.
I have task the required me to calculate the retention rate of the staff from each division on the company.
I want first to get number of employees per each division.
I have tried this:
$headers=#{}
$headers.Add("accept", "application/json")
$headers.Add("authorization", "Basic api")
$response = Invoke-WebRequest -Uri 'https://api.bamboohr.com/api/gateway.php/company/v1/employees/150/?fields=division' -Method GET -Headers $headers
$response
Result:
Content : {"id":"150","division":"######"}
However it retrieve only one one employee even if I remove the id from the url. And it's not what I am looking for, and I don't have idea on how to write it. It should return the number of employees in each division.
I’m building an application that fetches information from our Azure DevOps board. One of the tasks is to get all tickets present in a given column.
I’ve spent quite a lot of time reading through their docs but all the methods rely on you passing the IDS you want to get back, while what I’m looking for is for the API to tell me what work items do exist in a given column.
The easiest way to find the work items in a board column would be to use the Wiql - Query by Wiql API. The usage will look very similar to how you just use the UI query functionality to find work items.
Given some work items in this kind of board state (using Basic template):
Example in PowerShell below:
$AzureDevOpsAuthenicationHeader = #{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$uri = "https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=6.0"
$body = #{
"query" = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.BoardColumn] = 'Doing'"
} | ConvertTo-Json -Depth 10
Invoke-RestMethod -Method Post -Uri $uri -Headers $AzureDevOpsAuthenicationHeader -Body $body -ContentType 'application/json' |
Select-Object -ExpandProperty workItems
Returns:
id url
-- ---
26 https://dev.azure.com/{organization}/{project}/_apis/wit/workItems/26
Website I am attempting to do this on: https://www.netvendor.net/login
I am trying to login to the website automatically and kick off a script to create users in bulk for us.
If you run an Invoke-WebRequest on this page, it returns information, but nothing about the forms. They are simply not displayed. However, if you view the page source or inspect element, there are clearly forms on the page and they are not composed of JS or anything else that would mess it up. How can I get PowerShell to recognize these fields? I am using the following command:
Invoke-WebRequest -Uri "www.netvendor.net/login" -Method GET -UseBasicParsing
Because of the issue above, I decided I would just POST the information I needed by examining the request. The request requires three things:
email
password
_token
Unfortunately, the token is randomly generated each time a browser session is initiated. If you view source on the page and search for "_token", you will get the parameter that is needed. It doesn't seem like there is any way to retrieve this from the page? I am a bit lost as to what I can do at this point, especially since there is no API or anything else for me to work with.
For all interested, here is the final working script:
$nvlogin = Invoke-WebRequest "https://www.netvendor.net/login" -SessionVariable "netvendor"
$nvtoken = $nvlogin.InputFields.Where({ $_.Name -eq "_token" })[0].Value
$nvbody = #{
"_token" = $nvtoken
"email" = "your.name#website.com"
"password" = 'credentials'
}
Invoke-WebRequest -Uri "https://www.netvendor.net/login" -WebSession $netvendor -Method 'POST' -Body $nvbody
so this'll be the first time posting on the Google Dev Forum, fingers crossed I can get this resolved as I am pulling my hair out!
I have the following script in PowerShell. I have sorted the OAuth2 and I am able to hit my Calendar API and see the hits in the dashboard. So, authentication is fine. I used the API Explorer to get a rough idea of what I would need to send in order to create a new Calendar event, but in doing so I get a 400 error.
Here's the section I am running:
$requestUri = "https://www.googleapis.com/calendar/v3/calendars/mysite#blah.com/events?"
$body=#{
end='dateTime:2017-06-07T08:30:00+01:00'
start='dateTime:2017-06-07T08:00:00+01:00'
}
$json = $body | ConvertTo-Json
$header=#{Authorization = "Bearer $($tokens.access_token)"}
Invoke-RestMethod -Headers $header -Uri $requestUri -Method POST -Body
$json -ContentType 'application\json' -TransferEncoding gzip
Here is the error I receive:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
$json is formed like this:
{
"end": "dateTime:2017-06-07T08:30:00+01:00",
"start": "dateTime:2017-06-07T08:00:00+01:00"
}
I can remove transferEncoding and I get the same error.
As always, any help would be great :)
thanks
Moving my comment to an answer, the -ContentType looks weird with a backslash in it, and maybe it should be a forward slash, e.g.
$json -ContentType 'application/json'
I have a worksite that I am trying to "browse".
Done it with this...
$login = Invoke-WebRequest -Uri 'http://www.privateworksite.com' -SessionVariable GetIP
$form = $login.Forms[0]
$Form.Fields['ctl00$ContentPlaceHolder1$RadTextBox7']= "*******" <-- User ID goes here
$Form.Fields['ctl00$ContentPlaceHolder1$RadButton1'] = "submit" <-- Submit button
$afterfirstclick Invoke-WebRequest -Uri 'http://www.privateworksite.com' -WebSession $GetIP -Method POST -Body $form.Fields
Now that I am at the page I need to click on a new button that appears. I have tried to add a -sessionvariable $afterfirstclick but I get the dreaded PS Red lines stating that you cannot have -WebSession and -SessionVariable together.
ADDED INFO:
So how do I click on the button that is produced in $afterfirstclick? This is what I have for a button after the first click return.
ctl00$ContentPlaceHolder1$RadGrid1$ctl00$ctl04$GECBtnExpandColumn <-- a new button to create
a drop down table with the info I need. The table is not there prior to the
clicking the button so I need to click this button.
I have been all over and ever demo/post is about logging in to a site but after that how do you move around the site?
I have tried to feed $afterfirstclick into the -WebSession, bust...
Also tried to repeat the whole thing with the next Field to click the button and that just results in a new site not the "continuation" of the current.
Where to go from here?
Oh and the URL never changes so I cannot submit VIA URL.
Ok found the solution! I needed to feed $afterfirstclick into the next invoke-webrequest. I feel so stupid that it was not that obvious.
End result...
$url = "http://private.com" #<-- setup the URL
$tool = Invoke-WebRequest -Uri 'http://private.com' -UseDefaultCredentials -SessionVariable fb #<--create the site in a variable
write-host "1111111111111111" #<--just a marker to seperate the two requests so I can see the form.fields clearly
$Form = $tool.Forms[0] #<--first invoke form.fields
$Form.Fields #<--just printing them so I can see them
$Form.Fields['ctl00$ContentPlaceHolder1$RadTextBox7']= "USERID" #<--entering USERID into the form
$Form.Fields['ctl00$ContentPlaceHolder1$RadButton1'] = "submit" #<--clicking the submit button
$mainPage = Invoke-WebRequest ("$url" + $Form.Action) -WebSession $fb -Body $Form.Fields -Method Post #<--create the new page by calling the page with the fields
$mainPage.RawContent | out-file h:\response.html #<--sending it to a file so I can see the first page and second page side by side
write-host "2222222222222222" #<--just a marker to seperate the two requests so I can see the form.fields clearly
$Form2 = $mainPage.Forms[0] #<--pulling the new page form.fields NOTICE I am using the previous variable for the first invoke
$Form2.Fields #<--printing fields to take a look at what needs to be included in the next round
$Form2.Fields['ctl00$ContentPlaceHolder1$RadGrid1$ctl00$ctl04$GECBtnExpandColumn'] = "submit" #<--The newly generated button that needed to be clicked to continue
$mainPage2 = Invoke-WebRequest ("$url" + $Form2.Action) -WebSession $fb -Body $Form2.Fields -Method Post -UseDefaultCredentials #<--OK BIG ONE!! First the form.field needs to be correct as well as using the original -websession!!!
$mainPage2.RawContent | out-file h:\response1.html #<--output the second resulting page to compare
You have to watch that second request. It must use the first invoke to create new form.fields but still use the original -websession variable.
No idea why but this works this way, but I used this for another site to go deep into it so it is solid, just keep repeating the chain. You could even use a foreach loop with all the known form.fields.