Skip to content

Commit

Permalink
Merge pull request rubrikinc#186 from rubrikinc/Issue-Cleanup
Browse files Browse the repository at this point in the history
Issue-Cleanup
  • Loading branch information
jakerobinson authored Jul 13, 2021
2 parents fa5b445 + d4fd5ca commit b100f2a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
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

0 comments on commit b100f2a

Please sign in to comment.