• Home
  • Our Services
  • Presentations
  • About me
  • Links
  • Contact Us
  • Privacy Policy

Cloud and Datacenter Management

Cloud at your fingertips
  • Home
  • Our Services
  • Presentations
  • About me
  • Links
  • Contact Us
  • Privacy Policy
Home  /  SystemCenter  /  Setting SQL permissions with Powershell
19 November 2013

Setting SQL permissions with Powershell

Written by alexandre@verkinderen.com
SystemCenter powershell, sql, system center Leave a Comment

 

In the next couple of posts I’m going to blog about automating a System Center post-configuration deployment with Powershell. After you have deployed a typical SC environment you still need to do quite a lot of configuration. The following posts will cover how to automate this with Powershell.

 

The first powershell script is to define a specific user account as a sysadmin on a bunch of SQL servers:

[powershell]

<sub>#Variables
$Servers = @("srv01.contoso.com",”srv02.contoso.com”)</sub>

<sub>
#Connect remotely to the server</sub>

<sub>
Foreach($Server in $Servers)
{ </sub>

<sub>Invoke-Command -ComputerName $Server -ScriptBlock { </sub>

<sub>
#Set the system account as sysadmin</sub>

<sub>[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.SMO’) | out-null </sub>

<sub># Create SMO Connections to both SQL Instances
$Svr = New-Object (‘Microsoft.SqlServer.Management.Smo.Server’) "$server"
$svrole = $svr.Roles | where {$_.Name -eq ‘sysadmin’}
$svrole.AddMember("User account”)
}
}</sub>

[/powershell]

Thanks,

Alex

Related

Share On
Share on Facebook
Share on Twitter
Share on Google+
Share on LinkedIn
alexandre@verkinderen.com

 Previous Article Best of MMS 2013
Next Article   Powershell Deployment Toolkit failed missing port for sql server

Related Posts

  • Download MSIgnite 2018 slides

    02/10/2018
  • How to define an Azure Limited Admin custom role

    11/09/2017
  • Enabling Azure Network Security Group (NSG) flow logging in bulk

    06/06/2017

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Azure API Management Consumption Tier
  • Real Time Twitter sentiment analysis with Azure Cognitive Services
  • Move Managed Disks to another subscription
  • Download MSIgnite 2018 slides
  • Azure Files Updates from Ignite

Twitter

Goodreads

Tags

acs Advisor Agent Agents audit collection service azure Azure Cloud community cubesys end to end monitoring Essentials Events General hotfix HP Issue KB Management Pack manuals MVP Opalis Operations Manager 2007 Opmsgr 2007 R2 opsmgr opsmgr 2012 Opsmgr DB opsmgr R2 Performance powershell R2 reporting SCCM scom SCSM SCVMM service level dashboard Service Manager sql system center teched Uncategorized WAP web application monitoring Windows 2008

Categories

  • Azure
  • IOT
  • it camps
  • MAS
  • OMS
  • Powershell
  • Sharepoint
  • SystemCenter
  • Technet
  • Uncategorized
  • WAP
  • Windows 8

Archives

  • January 2019
  • November 2018
  • October 2018
  • September 2018
  • January 2018
  • December 2017
  • November 2017
  • September 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • November 2016
  • October 2016
  • September 2016
  • July 2016
  • June 2016
  • January 2016
  • December 2015
  • November 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • March 2014
  • January 2014
  • December 2013
  • November 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • November 2012
  • June 2011
  • May 2011
  • April 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
© Copyright 2017. Alexandre Verkinderen