Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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