question

Blackhawk-17 avatar image
Blackhawk-17 asked

Getting Basic Info via PowerShell

Hey gang, Anyone have a snippet to retrieve the default backup and data folders using PowerShell? Thanks!
powershell
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Blackhawk-17 avatar image Blackhawk-17 commented ·
I'll give the answer to @sqlaj but I'd still like to know if others get a blank on default installs or if the variables are populated.
0 Likes 0 ·
Oleg avatar image Oleg commented ·
@Blackhawk-17 I get the backup directory populated but other 2 are blanks.
0 Likes 0 ·
Blackhawk-17 avatar image Blackhawk-17 commented ·
@Oleg - if you change them in SSMS are they populated then? And if you change them back to the original defaults are they still populated (mine are)?
0 Likes 0 ·
sqlaj 1 avatar image
sqlaj 1 answered
See if this helps. You can paste this into Powereshell ISE and run. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null [System.reflection.assembly]::LoadWithPartialName('Microsoft.SqlServer.SMOExtended') | out-null $instance = gc env:computername #get the computername $s = new-object ("Microsoft.SqlServer.Management.Smo.Server") $instance $settings = $s.Settings $bkdir = $s.Settings.BackupDirectory #gets the backup directory $datafldr = $s.Settings.DefaultFile #gets the data directory $Logflder = $s.Settings.DefaultLog #gets the log directory $bkdir $datafldr $Logflder
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Blackhawk-17 avatar image Blackhawk-17 commented ·
Weird... it appears that Settings.DefaultFile and Settings.DefaultLog aren't "populated" until you actually set them to something. Can someone else try the code on a fresh install and see if they get the same experience of blank results?
0 Likes 0 ·
Fatherjack avatar image
Fatherjack answered
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Blackhawk-17 avatar image Blackhawk-17 commented ·
Getting the backup folder returned no problem... The data and log entries are coming back empty.
0 Likes 0 ·
sqlaj 1 avatar image
sqlaj 1 answered
We have drive and configuration standards for all SQL installs. By default SQL uses the install directory. Do you have databases on the server? Can you create a database within SSMS? Where does it put the data and log files? Here is a link to MSDN about default installation, may be of some help. http://msdn.microsoft.com/en-us/library/ms143547.aspx
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Blackhawk-17 avatar image Blackhawk-17 commented ·
I support many different Clients and, between various standards and legacy installs, I can not be assured that the default will be the correct location. Often the data files are on one SAN LUN under a Data directory and the log files are on a different LUN under Logs.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.