June 30, 2012 at 8:08 am
Guys,
Can you help me in providing the powershell script( or any link wheer i can get it)to check the db owner?I am very new to powershell
Thanks,
Mithra
July 1, 2012 at 7:28 pm
This should get you what you want using SMO:
param (
[string] $server,
[string] $database
)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") |
Out-Null
$sql_server = New-Object ("Microsoft.SqlServer.Management.Smo.Server") $server
$db = $sql_server.Databases.Item($database)
$db_owner = $db.Owner
Write-Host "$database Owner: $db_owner"
Save this as a script file and it can be called like:
.\GetDbOwner.ps1 -server YourServer\YourInstance -database YourDatabase
Here is a version-controlled copy of the above script for future reference.
July 1, 2012 at 10:27 pm
WHY are we making a trip to Powershell for this property???
--Jeff Moden
Change is inevitable... Change for the better is not.
July 1, 2012 at 11:16 pm
Thanks a lot,Thomas!!!!
July 2, 2012 at 3:21 am
Jeff Moden (7/1/2012)
WHY are we making a trip to Powershell for this property???
Well, I used something like this once to check ~30 instances for any db's that still had the previous DBA as the owner. 🙂
July 2, 2012 at 6:36 am
Thanks guys... I understand why some of us might do such a thing but I really want to know why the OP wants to do it. If it's not for something like multiple servers, then there are much easier ways to get this information than a trip to Powershell.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 2, 2012 at 6:41 am
Jeff Moden (7/2/2012)
Thanks guys... I understand why some of us might do such a thing but I really want to know why the OP wants to do it. If it's not for something like multiple servers, then there are much easier ways to get this information than a trip to Powershell.
Oh absolutely, I couldn't agree more. If this is a single instance then that'd be like building a clock just to find out what time it is.
July 2, 2012 at 6:57 am
Jeff Moden (7/2/2012)
Thanks guys... I understand why some of us might do such a thing but I really want to know why the OP wants to do it. If it's not for something like multiple servers, then there are much easier ways to get this information than a trip to Powershell.
Very true. I think at the time, I was also trying to teach myself Powershell; and this was a an easy query to compare expected results with the actual values.
I'm still rubbish at PS though 😀
July 2, 2012 at 7:11 am
Thomas Stringer (7/2/2012)
Jeff Moden (7/2/2012)
Thanks guys... I understand why some of us might do such a thing but I really want to know why the OP wants to do it. If it's not for something like multiple servers, then there are much easier ways to get this information than a trip to Powershell.Oh absolutely, I couldn't agree more. If this is a single instance then that'd be like building a clock just to find out what time it is.
BWAA-HAAA!!! I love the analogy! Thanks for the great laugh, Thomas... and on a Monday morning, no less. 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
July 2, 2012 at 8:12 am
Jeff Moden (7/2/2012)
Thomas Stringer (7/2/2012)
Jeff Moden (7/2/2012)
Thanks guys... I understand why some of us might do such a thing but I really want to know why the OP wants to do it. If it's not for something like multiple servers, then there are much easier ways to get this information than a trip to Powershell.Oh absolutely, I couldn't agree more. If this is a single instance then that'd be like building a clock just to find out what time it is.
BWAA-HAAA!!! I love the analogy! Thanks for the great laugh, Thomas... and on a Monday morning, no less. 🙂
😀 Glad I could provide some Monday morning humor!!!
July 2, 2012 at 11:45 am
i'm a dinosaur and prefer good old T-SQL 🙂
USE [SomeDB]
GO
SELECT 'The database owner is: ' + QUOTENAME(SUSER_SNAME(dp.sid))
FROM sys.database_principals dp
WHERE dp.name = 'dbo'
GO
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply