<commit_before>Set-Location -Path "$home\Dropbox\github\tsql-snippets\powershell-sql\run_script_on_all_dbs"



#	This top zone sets up the variables for the script to run. 

#

#	I am working on moving the configuration to another file to make mistakes more apparent when modifying configuration, and making sure to test if they input sane information



$serverName = "example-pc"



#

#	Dont touch anything under here

#



Push-Location

	Import-Module "sqlps" -DisableNameChecking

Pop-Location



# add-type assemblies taken from http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/06/10-tips-for-the-sql-server-powershell-scripter.aspx however I might not need it for this script

add-type -AssemblyName "Microsoft.SqlServer.ConnectionInfo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -ErrorAction Stop

add-type -AssemblyName "Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -ErrorAction Stop

add-type -AssemblyName "Microsoft.SqlServer.SMOExtended, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -ErrorAction Stop

add-type -AssemblyName "Microsoft.SqlServer.SqlEnum, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -ErrorAction Stop

add-type -AssemblyName "Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -ErrorAction Stop



if ($sqlServer -eq $null) # added because powergui really wants to keep this variable in scope even though a powershell window wont, still an awesome program http://powergui.org

{

	New-Variable -name "sqlServer" -Value $(new-object ("Microsoft.SqlServer.Management.Smo.Server") $serverName) -Scope script

	$sqlServer.ConnectionContext.StatementTimeout = 0 # timeout taken from http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/06/10-tips-for-the-sql-server-powershell-scripter.aspx

}







# initial data from http://technet.microsoft.com/en-us/library/ee692794.aspx

$a = 

@{Expression={$_.DisplayName};Label="Property"},

@{Expression={$_.ConfigValue};Label="Value"}, `

@{Expression={$_.Description};Label="Description"}



foreach ($config in $sqlServer.Configuration.Properties)

{

	$config | fl $a

	

}<commit_msg>bunch of changes, but this is broken atm<commit_after>param(

		[string]$serverName = "example-pc", 

		[string]$propertyFile = 'propertyfile.csv', 

		[string]$dbFile = 'databases.csv'

)



Set-Location -Path "$home\Dropbox\github\tsql-snippets\powershell-sql\run_script_on_all_dbs"



#

#	Dont touch anything under here

#



Push-Location

	Import-Module "sqlps" -DisableNameChecking

Pop-Location



# add-type assemblies taken from http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/06/10-tips-for-the-sql-server-powershell-scripter.aspx however I might not need it for this script

add-type -AssemblyName "Microsoft.SqlServer.ConnectionInfo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -ErrorAction Stop

add-type -AssemblyName "Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -ErrorAction Stop

add-type -AssemblyName "Microsoft.SqlServer.SMOExtended, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -ErrorAction Stop

add-type -AssemblyName "Microsoft.SqlServer.SqlEnum, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -ErrorAction Stop

add-type -AssemblyName "Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -ErrorAction Stop



if ($sqlServer -eq $null) # added because powergui really wants to keep this variable in scope even though a powershell window wont, still an awesome program http://powergui.org

{

	New-Variable -name "sqlServer" -Value $(new-object ("Microsoft.SqlServer.Management.Smo.Server") $serverName) -Scope script

	$sqlServer.ConnectionContext.StatementTimeout = 0 # timeout taken from http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/06/10-tips-for-the-sql-server-powershell-scripter.aspx

}



# initial data from http://technet.microsoft.com/en-us/library/ee692794.aspx

$a = 

@{Expression={$_.DisplayName};Label="Property"},

@{Expression={$_.ConfigValue};Label="Value"}, `

@{Expression={$_.Description};Label="Description"}



[array]$sprocs



# still need to understand objects in posh and use some of the more terse syntax, I am too used to string manipulation instead of object manipulation

$sqlServer.Databases | where {$dontrun -NotContains $_} | 

	foreach $_ {			

		Write-Host $_

		foreach ($proc in $_.StoredProcedures){

			

			IF ($proc.IsSystemObject -eq $false){					

					$sprocs+=$proc.Name					

				}

			

		}

		

		

} 

ForEach-Object {$sprocs | select $_ } | out-file "items.csv"



$sqlServer.Configuration.Properties | Export-Csv $propertyFile -NoTypeInformation

$sqlServer.Databases | Export-Csv $dbFile -NoTypeInformation


{'fraction_non_alphanumeric': 0.5555101623940354, 'fraction_numerical': 0.021856807271984476, 'mean_word_length': 10.52, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1367239', 'n_tokens_mistral': 9736, 'n_tokens_neox': 9736, 'n_words': 350}