SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


script Powershell simple to recovery mode


script Powershell simple to recovery mode

Author
Message
ABDALLAH mehdoini
ABDALLAH mehdoini
Valued Member
Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)

Group: General Forum Members
Points: 68 Visits: 336
Hello
I will need to set up an automatism
that checks the recovery mode of the bases
If base other than SIMPLE, force the transition to simple mode and shrink database
import-module sqlps -DisableNameChecking
#[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
Add-Type -AssemblyName "Microsoft.SqlServer.Smo"
#Force change psdrive from SQLserver to c:\ -> without UNC link not working
cd c:
$mode_recuperation='simple'
$Server='sqlprod'
$SMOserver = New-Object ('Microsoft.SqlServer.Management.Smo.Server') -argumentlist $Server
$SMOserver.Databases | where {$_.IsSystemObject -eq $false} | select Name, RecoveryModel | Format-Table # Ce ci pour enlever les bases systéme
$SMOserver.Databases | where {$_.IsSystemObject -eq $false} | foreach {$_.RecoveryModel = [Microsoft.SqlServer.Management.Smo.RecoveryModel]::Simple; $_.Alter()}#Forcer le passage vers database simpel
$SMOserver.Databases | where {$_.IsSystemObject -eq $false} | select Name, RecoveryModel | Format-Table #simple affichage


Who has an idea how I can modify my script to add the shrink part ?
Phil Parkin
Phil Parkin
SSC Guru
SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)

Group: General Forum Members
Points: 138683 Visits: 22899
Before you go ahead with this, are you aware of possible issues with shrinking databases?
You may like to read here for more information.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
ABDALLAH mehdoini
ABDALLAH mehdoini
Valued Member
Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)

Group: General Forum Members
Points: 68 Visits: 336
yes
or it is an exceptional action
I have to run it only if I have disk saturation

Phil Parkin
Phil Parkin
SSC Guru
SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)SSC Guru (138K reputation)

Group: General Forum Members
Points: 138683 Visits: 22899
joujousagem2006 1602 - Tuesday, January 30, 2018 7:28 AM
yes
or it is an exceptional action
I have to run it only if I have disk saturation

Doesn't that mean that your database needs more disk space?
Changing recovery mode to simple is not an exceptional action.



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Steve Jones
Steve Jones
SSC Guru
SSC Guru (353K reputation)SSC Guru (353K reputation)SSC Guru (353K reputation)SSC Guru (353K reputation)SSC Guru (353K reputation)SSC Guru (353K reputation)SSC Guru (353K reputation)SSC Guru (353K reputation)

Group: Administrators
Points: 353658 Visits: 20214
Not that I think this is a good idea, but once you have the db, or db files, you would use a PoSh command to execute dbcc shrinkdatabase or dbccshrinkfile.

You would be better off using placeholders to free up space when needed and then deal with the issue.

https://voiceofthedba.com/2014/12/01/creating-placeholder-files/

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search