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


SMO Missing properties


SMO Missing properties

Author
Message
Jeff Shurak
Jeff Shurak
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2051 Visits: 831
I have a server that seems to be missing some properties when accessing via SMO in powershell, specifically the default data and log file locations. These can be viewed through ssms and tsql. Has anyone encountered this before?
Lowell
Lowell
SSC Guru
SSC Guru (294K reputation)SSC Guru (294K reputation)SSC Guru (294K reputation)SSC Guru (294K reputation)SSC Guru (294K reputation)SSC Guru (294K reputation)SSC Guru (294K reputation)SSC Guru (294K reputation)

Group: General Forum Members
Points: 294919 Visits: 42110
thos locations are stored in the registry, and not in any table, or as a property of a server, as far as i know.
...how are you getting them via powershell?

i get them via a TSQL like this:

EXECUTE [master].dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer',
N'BackupDirectory';
EXECUTE [master].dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer',
N'DefaultData';
EXECUTE [master].dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer',
N'DefaultLog';



Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Jeff Shurak
Jeff Shurak
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2051 Visits: 831
Lowell I can grab them that way and might if need be, but ideally in powershell. Its pretty straight forward in powershell


$Instance = New-Object('Microsoft.SqlServer.Management.Smo.Server') $InstanceName
$Instance.DefaultFile
$Instance.DefaultLog




These are blank for a specific instance,but populated for the majority of other instances.
Jeff Shurak
Jeff Shurak
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2051 Visits: 831
It looks like it might be a registry issue. There don't appear to be DefaultFile and DefaultLog entries in the standard location. Thanks for pointing me down the right path.
tibileo
tibileo
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 7
You might want to try additional properties, because maybe the user does not have rights to VIEW SERVER STATE/DEFINITION .
Or maybe the 2 properties are not being initialized because of the location of the user database files.

Try the following alternatives:


[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$server = new-object ('Microsoft.SqlServer.Management.Smo.Server') 'localhost'
$setting1 = $server.Settings.DefaultFile
$setting2 = $server.Settings.DefaultLog
$setting3 = $server.Information.MasterDBPath
$setting4 = $server.Information.MasterDBLogPath
$setting5 = $server.InstallDataDirectory


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