Skip to content

Instantly share code, notes, and snippets.

@martin9700
Created January 4, 2015 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save martin9700/db6e6040ada30b26d8be to your computer and use it in GitHub Desktop.
Save martin9700/db6e6040ada30b26d8be to your computer and use it in GitHub Desktop.
ForEach ($Select in $Selected)
{
$Type = [int](-not $Database)
$Name = (Invoke-SQLQuery -Instance $Instance -Database Master -MultiSubnetFailover -Query "Select name From sys.master_files Where database_id = '$($Select.ID)' And type = $Type").Name
If ($Name)
{
Write-Verbose "$(Get-Date): Shrinking $($Select.Name) database/log file: $Name"
$Result = Invoke-SQLQuery -Instance $Instance -Database $Select.Name -MultiSubnetFailover -Query "DBCC SHRINKFILE($Name,1)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment