Last active
June 4, 2020 10:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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