-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExport-PlaceInfoForBlogs.ps1
64 lines (52 loc) · 1.7 KB
/
Export-PlaceInfoForBlogs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Clear-Host
$username = ""
$password = ""
$userpass = $username + ":" + $password
$bytes= [System.Text.Encoding]::UTF8.GetBytes($userpass)
$encodedlogin=[Convert]::ToBase64String($bytes)
$authheader = "Basic " + $encodedlogin
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization",$authheader)
$headers.Add("Accept","application/json")
$hosturi = "https://{baseurl}/api/core/v3"
$placeId = "1001"
$objTemplate = @{
'html'=$null
'parent' = $null
'placeID' = $null
'type' = $null
'displayName' = $null
'name' = $null
'groupType' = $null
}
$array = @()
$url = "{0}/places?fields=parent,placeID,type,displayName,name,groupType,resources.html&filter=type(blog)" -f $hosturi
$LogFileName = $("E:\LogFiles\BlogsInfo-{0}.txt" -f (Get-Date -Format "yyyy-MM-dd HHmm"))
$keepLooping = $true
while ( $keepLooping -eq $true )
{
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
foreach ($item in $response.list)
{
$obj = New-Object -TypeName PSObject -Property $objTemplate
$obj.'placeID' = $item.placeID
$obj.'type' = $item.type
$obj.'displayName' = $item.displayName
$obj.'name' = $item.name
$obj.'groupType' = $item.groupType
$obj.'parent' = $item.parent
$obj.'html' = $item.resources.html.ref
write-host $("{0} {1}" -f $item.placeID,$item.name)
$array += $obj
}
if ( $response.links.next -ne $null)
{
$url = $response.links.next
write-host $("url = {0}" -f $url)
}
else
{
$keepLooping = $false
}
}
$array | Export-Csv $LogFileName -NoTypeInformation