Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-Cleanup #186

Merged
merged 5 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.creds
Export-RubrikDatabasesJobFile - DN Test.json
.idea
.DS_Store
37 changes: 29 additions & 8 deletions Sizing/DBSizingQueries/CollectSQLProfile.ps1
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
[cmdletbinding()]
<#
.SYNOPSIS
MSSQL Database Sizing Scripts for Rubrik

.EXAMPLE
To run the script use the below command with the SQLInstance parameter. Then provide that parameter with a comma separated list of SQL Servers. The script will use Windows Authentication to collect data.
PS C:\> .\CollectSQLProfile.ps1 -SQLInstance SQL1, SQL2, SQL3, SQL4\Instance1

.EXAMPLE
If you need to use SQL Authentication instead of Windows Authentication, then include the Credential parameter and provide it with a user name. You will be prompted for a password.
PS C:\> .\CollectSQLProfile.ps1 -SQLInstance SQL1, SQL2, SQL3, SQL4\Instance1 -Credential sa

.EXAMPLE
Instead of giving a comma separated list of sql servers, you can use the InstancesFile parameter. Provide a file that contains a list of sql server instances. Each instance should be on a separate line.
PS C:\> .\CollectSQLProfile.ps1 -InstancesFile SQLInstances.txt
.NOTES
Name: MSSQL Database Sizing Scripts for Rubrik
Author: Mike Fal, Chris Lumnah
#>
[cmdletbinding()]
param(
[Parameter(ParameterSetName='List Of Instances')]
[string[]] $SQLInstance,
[Parameter(ParameterSetName='File Of Instances')]
[String] $InstancesFile,
[string] $OutPath = [Environment]::GetFolderPath("MyDocuments"),
[string] $QueryPath = '.\',
[Switch] $Anonymize,
Expand All @@ -16,8 +38,12 @@ BEGIN{
$queries = Get-ChildItem $QueryPath -Filter "*.sql"
$queries | ForEach-Object {$_ | Add-Member -MemberType NoteProperty -Name FileName -Value "$($_.Name.Replace('.sql',''))-$(Get-Date -Format 'yyyyMMddHHmm').csv"}
$header = $true
if (![string]::IsNullOrEmpty($InstancesFile)){
if (Test-Path $InstancesFile){
$SQLInstance = Get-Content -Path $InstancesFile
}
}
}

PROCESS{
foreach($i in $SQLInstance){
$svr = new-object "Microsoft.SqlServer.Management.Smo.Server" $i;
Expand All @@ -41,12 +67,7 @@ PROCESS{
$OutFile = Join-Path -Path $OutPath -ChildPath $q.filename

Write-Verbose "Collecting data from $i"
# if($SqlUser -and $SqlPassword){
# $output = Invoke-SqlCmd -ServerInstance "$i" -Database TempDB -Query "$sql" -Username $SqlUser -Password $SqlPassword
# }
# else{
$output = Invoke-SqlCmd -ServerInstance "$i" -Database TempDB -Query "$sql" -Credential $Credential
# }
$output = Invoke-SqlCmd -ServerInstance "$i" -Database TempDB -Query "$sql" -Credential $Credential

if($header -eq $true){
$output | ConvertTo-Csv -Delimiter '|' -NoTypeInformation | Out-File $OutFile -Append
Expand Down
4 changes: 4 additions & 0 deletions Sizing/DBSizingQueries/SQLInstances.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
am1-chrilumn-w1\sql2019
am1-chrilumn-w1\sql2017
am1-sql16-1
am1-sql17-1