Skip to content

Instantly share code, notes, and snippets.

@jcallaghan
Last active June 4, 2020 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcallaghan/a59ff97f70f56a41652fab767d14e7f8 to your computer and use it in GitHub Desktop.
Save jcallaghan/a59ff97f70f56a41652fab767d14e7f8 to your computer and use it in GitHub Desktop.
Remotely create a number of content databases using New-SPContentDatabase > https://docs.microsoft.com/en-us/powershell/module/sharepoint-server/new-spcontentdatabase?view=sharepoint-ps
# Remotely create a number of content databases using New-SPContentDatabase
# https://docs.microsoft.com/en-us/powershell/module/sharepoint-server/new-spcontentdatabase
$SPServers = @("server1")
$webApp = "https://webapp.domain.com"
$databasesRequired = 10
$databasePrefix = "AG5Q_Prefix_Content"
$databaseServer = "DBserver.domain.com"
# Prepare remote PS session and load SP module
$remoteSession = New-PSSession –ComputerName $SPServers[0]
Invoke-Command -Session $remoteSession -ScriptBlock {Add-PSSnapin Microsoft.SharePoint.PowerShell;}
# Loop through and create new content databases
for ($i = 1; $i -le $databasesRequired; $i+=1){
$db = "$($databasePrefix)$(([string]$i).PadLeft(3,'0'))"
Invoke-Command -Session $remoteSession -ScriptBlock {New-SPContentDatabase $($args[0]) -DatabaseServer $args[1] -WebApplication $args[2] } -ArgumentList $db, $databaseServer, $webApp
}
# Disconnect PS session
Disconnect-PSSession $remoteSession
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment