Do any folk here use SMO from PowerShell?
I've found a limited number of web postings about the subject, but not much newsgroup/forum chat.
Specifically, I'm wondering how to capture exceptions raised by SMO calls.
For example, I wanted to drop all logins on a server, so thought I'd try this:
$sql = new-object 'microsoft.sqlserver.management.smo.server' 'servername'
$sql.Logins | %{$_.Drop()}
which throws this error for every login:
Exception calling "Drop" with "0" argument(s): "Drop failed for Login 'BloggsJ'. "
At line:1 char:24
+ $sql.Logins | %{$_.drop( <<<< )}
Is there more information to be had? I've tried defining an object as microsoft.sqlserver.management.smo.smoexception but I'm not quite sure what to do with it...
TIA,
Robin.
Do a search on the web for "PowerSMO" and you will find a number of tutorials I wrote on using SMO and PowerShell.
Dan
No comments:
Post a Comment