<commit_before>﻿function Save-DbaDiagnosticQueryScript {
<#
.SYNOPSIS 
Save-DbaDiagnosticQueryScript downloads the most recent version of all Glenn Berry DMV scripts

.DESCRIPTION
The dbatools module will have the diagnostice queries pre-installed. Use this only to update to a more recent version or specific versions.

This function is mainly used by Invoke-DbaDiagnosticQuery, but can also be used independently to download the Glenn Berry DMV scripts.

Use this function to pre-download the scripts from a device with an Internet connection.
	
The function Invoke-DbaDiagnosticQuery will try to download these scripts automatically, but it obviously needs an internet connection to do that.

.PARAMETER Path
Specifies the path to the output
	
.PARAMETER Silent
Use this switch to disable any kind of verbose messages

.NOTES
Author: <NAME> (@AndreKamman), http://clouddba.io

dbatools PowerShell module (https://dbatools.io, <EMAIL>)
Copyright (C) 2016 <NAME>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

.EXAMPLE   
Save-DbaDiagnosticQueryScript -Path c:\temp

Downloads the most recent version of all Glenn Berry DMV scripts to the specified location.
If Path is not specified, the "My Documents" location will be used

#>
	[CmdletBinding()]
	param (
		[System.IO.FileInfo]$Path = [Environment]::GetFolderPath("mydocuments"),
		[Switch]$Silent
	)
	Add-Type -AssemblyName System.Web
	Write-Message -Level Output -Message "Downloading SQL Server Diagnostic Query scripts"
	
	$glenberryrss = "http://www.sqlskills.com/blogs/glenn/feed/"
	$glenberrysql = @()
	
	$rss = Invoke-WebRequest -uri $glenberryrss -UseBasicParsing
	
	foreach ($link in $rss.Links.outerHTML) {
		if ($link -Match "https:\/\/dl.dropboxusercontent*(.+)\/SQL(.+)\.sql") {
			$URL = $matches[0]
			
			if ([System.Web.HttpUtility]::UrlDecode($URL) -Match "SQL Server (.+) Diagnostic") {
				$SQLVersion = $matches[1].Replace(" ", "")
			}
			
			if ([System.Web.HttpUtility]::UrlDecode($URL) -Match "\((.+) (.+)\)") {
				$FileYear = "{0}" -f $matches[2]
				[int]$MonthNr = [CultureInfo]::InvariantCulture.DateTimeFormat.MonthNames.IndexOf($matches[1]) + 1
				$FileMonth = "{0:00}" -f $MonthNr
			}
			
			$glenberrysql += [pscustomobject]@{
				URL = $URL
				SQLVersion = $SQLVersion
				FileYear = $FileYear
				FileMonth = $FileMonth
				FileVersion = 0
			}
		}
	}
	
	foreach ($group in $glenberrysql | Group-Object FileYear) {
		$maxmonth = "{0:00}" -f ($group.Group.FileMonth | Measure-Object -Maximum).Maximum
		foreach ($item in $glenberrysql | Where-Object FileYear -eq $group.Name) {
			if ($item.FileMonth -eq "00") {
				$item.FileMonth = $maxmonth
			}
		}
	}
	
	foreach ($item in $glenberrysql) {
		$item.FileVersion = "$($item.FileYear)$($item.FileMonth)"
	}
	
	foreach ($item in $glenberrysql | Sort-Object FileVersion -Descending | Where-Object FileVersion -eq ($glenberrysql.FileVersion | Measure-Object -Maximum).Maximum) {
		$filename = "{0}\SQLServerDiagnosticQueries_{1}_{2}.sql" -f $Path, $item.SQLVersion, $item.FileVersion
		Invoke-WebRequest -Uri $item.URL -OutFile $filename
	}
}
<commit_msg>added verbosity<commit_after>﻿function Save-DbaDiagnosticQueryScript {
<#
.SYNOPSIS 
Save-DbaDiagnosticQueryScript downloads the most recent version of all Glenn Berry DMV scripts

.DESCRIPTION
The dbatools module will have the diagnostice queries pre-installed. Use this only to update to a more recent version or specific versions.

This function is mainly used by Invoke-DbaDiagnosticQuery, but can also be used independently to download the Glenn Berry DMV scripts.

Use this function to pre-download the scripts from a device with an Internet connection.
	
The function Invoke-DbaDiagnosticQuery will try to download these scripts automatically, but it obviously needs an internet connection to do that.

.PARAMETER Path
Specifies the path to the output
	
.PARAMETER Silent
Use this switch to disable any kind of verbose messages

.NOTES
Author: <NAME> (@AndreKamman), http://clouddba.io

dbatools PowerShell module (https://dbatools.io, <EMAIL>)
Copyright (C) 2016 <NAME>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

.EXAMPLE   
Save-DbaDiagnosticQueryScript -Path c:\temp

Downloads the most recent version of all Glenn Berry DMV scripts to the specified location.
If Path is not specified, the "My Documents" location will be used

#>
	[CmdletBinding()]
	param (
		[System.IO.FileInfo]$Path = [Environment]::GetFolderPath("mydocuments"),
		[Switch]$Silent
	)
	Add-Type -AssemblyName System.Web
	
	Write-Message -Level Output -Message "Downloading SQL Server Diagnostic Query scripts"
	
	$glenberryrss = "http://www.sqlskills.com/blogs/glenn/feed/"
	$glenberrysql = @()
	
	Write-Message -Level Output -Message "Downloading $glenberryrss"
	$rss = Invoke-WebRequest -uri $glenberryrss -UseBasicParsing
	
	foreach ($link in $rss.Links.outerHTML) {
		if ($link -Match "https:\/\/dl.dropboxusercontent*(.+)\/SQL(.+)\.sql") {
			$URL = $matches[0]
			
			if ([System.Web.HttpUtility]::UrlDecode($URL) -Match "SQL Server (.+) Diagnostic") {
				$SQLVersion = $matches[1].Replace(" ", "")
			}
			
			if ([System.Web.HttpUtility]::UrlDecode($URL) -Match "\((.+) (.+)\)") {
				$FileYear = "{0}" -f $matches[2]
				[int]$MonthNr = [CultureInfo]::InvariantCulture.DateTimeFormat.MonthNames.IndexOf($matches[1]) + 1
				$FileMonth = "{0:00}" -f $MonthNr
			}
			
			$glenberrysql += [pscustomobject]@{
				URL = $URL
				SQLVersion = $SQLVersion
				FileYear = $FileYear
				FileMonth = $FileMonth
				FileVersion = 0
			}
		}
	}
	
	foreach ($group in $glenberrysql | Group-Object FileYear) {
		$maxmonth = "{0:00}" -f ($group.Group.FileMonth | Measure-Object -Maximum).Maximum
		foreach ($item in $glenberrysql | Where-Object FileYear -eq $group.Name) {
			if ($item.FileMonth -eq "00") {
				$item.FileMonth = $maxmonth
			}
		}
	}
	
	foreach ($item in $glenberrysql) {
		$item.FileVersion = "$($item.FileYear)$($item.FileMonth)"
	}
	
	foreach ($item in $glenberrysql | Sort-Object FileVersion -Descending | Where-Object FileVersion -eq ($glenberrysql.FileVersion | Measure-Object -Maximum).Maximum) {
		$filename = "{0}\SQLServerDiagnosticQueries_{1}_{2}.sql" -f $Path, $item.SQLVersion, $item.FileVersion
		Write-Message -Level Output -Message "Downloading $($item.URL) to $filename"
		Invoke-WebRequest -Uri $item.URL -OutFile $filename
	}
}

{'fraction_non_alphanumeric': 0.1112259398010593, 'fraction_numerical': 0.005942384704818499, 'mean_word_length': 4.161333333333333, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4369651', 'n_tokens_mistral': 2530, 'n_tokens_neox': 2290, 'n_words': 819}