-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-gtmetrix.ps1
58 lines (51 loc) · 1.8 KB
/
check-gtmetrix.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
#
# Script.ps1
#
function add-credentials {
# credentials is encrypted with
# read-host -assecurestring | convertfrom-securestring | out-file C:\auth\password.txt
$dbpassword = Get-Content C:\auth\sa.txt | convertto-securestring
$dbcred = new-object -typename System.Management.Automation.PSCredential -argumentlist sa, $dbpassword
set-variables
}
function set-variables {
for ($i=0; $i -lt (Get-Content cfg-mgmt.conf).length; $i++) {
$line = (Get-Content $randFolderName\$gitpath\cfg-mgmt.conf | select -first 1 -skip $i)
write-host "creating value for "$line.Split('=')[0]
New-Variable -Name $line.Split('=')[0] -Value $line.Split('=')[1]
}
get-sitesfromDB
}
function get-sitesfromDB {
Invoke-
set-header
}
function set-header {
$user = $email
$password = $apikey
$pair = "${user}:${password}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }
start-test
}
function start-test {
$postParams = @{"url"='https://increo.no';"x-metrix-adblock"=0;"location"=2;"browser"=1}
$gtmetrix = (Invoke-webrequest -uri https://gtmetrix.com/api/0.1/test -method POST -Headers $headers -Body $postParams)
$test_id = ($gtmetrix.Content | ConvertFrom-Json).test_id
add-todatabase
}
function set-values {
$gtreport = (Invoke-WebRequest -uri https://gtmetrix.com/api/0.1/test/$test_id -Headers $headers)
$gtreport = $gtreport.Content | ConvertFrom-Json
[float]$time = $gtreport.results.onload_time / 1000
[int]$pageelements = $gtreport.results.page_elements
[int]$yslow = $gtreport.results.yslow_score
[int]$pagespeed = $gtreport.results.pagespeed_score
add-2db
}
function add-2db {
Invoke-Sqlcmd
}
add-credentials