Skip to content

Instantly share code, notes, and snippets.

@Veretax
Created October 21, 2019 20:06
Show Gist options
  • Save Veretax/bea7eb8d82ccb135ab913bdacd40a25b to your computer and use it in GitHub Desktop.
Save Veretax/bea7eb8d82ccb135ab913bdacd40a25b to your computer and use it in GitHub Desktop.
Copy Sitefinity Theme to Server from local Desktop
##############################################################################################################################
#
# Backup Themes on Server
# Author: Timothy Western
# Last Modified: 2019/10/21 15:30
#
# This script will backup the Theme designated as ThemeName, masterpages, and styles and javascript to a folder on C Drive
# This is part 1 of a 3 Script Process (recommend executing copy_themes_toserver which calls all three parts.)
# (This script requires no special permissions)
#
# License: MIT Free to use, royalty free for ever, just thank me in the credits if you publish them.
#
# Sitefinity note, this assumes the theme is already registered with Sitefinity, if not, see their Website for more info
#
##############################################################################################################################
# BackUp Themes and Master Pages
$TimeStamp = get-date -f yyyyMMdd-hhmmss
$WebsiteTemplateSource = "C:\inetpub\wwwroot\{SiteFinityAppFolderinIIS}\App_Data\Sitefinity\WebsiteTemplates\"
$WebsiteTemplateBackupRoot = "C:\Backups\Themes\Archives\$TimeStamp\"
$WebsiteTemplateBackupDestination = $WebsiteTemplateBackupRoot + "\WebsiteTemplates\"
if ([string]::IsNullOrWhiteSpace($ThemeName)) {
$ThemeName = "Theme 1"
}
$ArchivePath = $WebsiteTemplateBackupRoot + $ThemeName + "-ThemeBackup-$TimeStamp.zip"
echo "Creating backup for Theme: $ThemeName"
echo "Backup Archive set to: $WebsiteTemplateBackupRoot"
echo "Create new timestamped backup directory"
New-Item -ItemType directory -Path $WebsiteTemplateBackupDestination -Force
echo "Backing up Website Templates, Master Page and Themes at: $WebsiteTemplateSource"
echo "Will be copied to Folder at: $WebsiteTemplateBackupRoot"
$excludes = "old", "original", "Archives", "Old", "Original", "Any Other Folder you would like to ignore"
Get-ChildItem $WebsiteTemplateSource -Directory |
Where-Object{$_.Name -notin $excludes} |
Copy-Item -Destination $WebsiteTemplateBackupDestination -Recurse -Force
## ToDo Filter out objects check
echo "Compressing archive at: $WebsiteTemplateBackupRoot"
echo "Backup Path: $ArchivePath"
Compress-Archive -DestinationPath $ArchivePath -LiteralPath $WebsiteTemplateBackupDestination -CompressionLevel Optimal
echo "WebsiteTemplate Backup Completed!"
##############################################################################################################################
#
# Install Themes to Server
# Author: Timothy Western
# Last Modified: 2019/10/21 15:30
#
# This script will manage a 3 part process:
# 1. to backup the master pages and themes currently in sitefinity (calling backup_themes_on_server.ps1)
# 2. grab a temporary copy of themes from a user machine and copy into the temp directory on c drive (this file)
# 3. Then install a copy locally into the wwwroot folder for IIS Foldername for sitefinity account for the theme
# (calling install_themes_to_server.ps1)
#
# This is part 2 of a 3 Script Process (recommend executing copy_themes_toserver which calls all three parts.)
# (This script requires the source of the themes to have Windows Remote Management (WinRM) is started (delayed)
# It prompts for your credentials using the default defined below.
#
# License: MIT Free to use, royalty free for ever, just thank me in the credits if you publish them.
#
# Sitefinity note, this assumes the theme is already registered with Sitefinity, if not, see their Website for more info
#
##############################################################################################################################
$Destination = "C:\temp\{myappthemes}"
$ServerName = "ServerName1"
$MasterPageSource = "C:\{PathToSitefinitySource}\App_Data\WebsiteTemplates\{ThemeName}\App_Master"
$SourceFolder = "C:\{PathToSitefinitySource}\App_Data\WebsiteTemplates\{ThemeName}\App_Themes"
$ThemeName = "Theme1"
$SourceRoot = $SourceFolder+"\"+$ThemeName
$DestinationRoot = $Destination + "\" + $ThemeName
"Preparing to Backup Master Pages and Themes"
& ".\backup_themes_on_server.ps1"
### Actual part of Copy_Themes_to_Server.ps1 ###
echo ""
echo ""
echo "Preparing to Copy from: $SourceRoot"
echo "Copying to: $DestinationRoot"
# Check for existing directory"
if (-not (Test-Path -LiteralPath $DestinationRoot)) {
#New-Item -ItemType directory -Path $DestinationRoot -Force
"Successfully created directory $DestinationRoot."
}
else {
"Directory $DestinationRoot already existed"
Get-ChildItem -Path $DestinationRoot -Force -Recurse | Remove-Item -force -recurse
Remove-Item $DestinationRoot -Force -Recurse
"Removing old copies"
# # New-Item -ItemType directory -Path $DestinationRoot -Force
}
$Session = New-PSSession -ComputerName "YOURPCNAME" -Credential "USERGROUP\USERNAME"
Copy-Item $SourceRoot -Destination $Destination -FromSession $Session -Recurse
Copy-Item $MasterPageSource -Destination $Destination -FromSession $Session -Recurse -Force
"Preparing to Install Master Page and Theme"
& ".\install_themes_to_server.ps1"
##############################################################################################################################
#
# Install Themes to Server
# Author: Timothy Western
# Last Modified: 2019/10/21 15:30
#
# This script will Take a temporary copy of themes copied from the temp directory and copy them into Server wwwroot
# folder for Sitefinity.
# This is part 3 of a 3 Script Process (recommend executing copy_themes_toserver which calls all three parts.)
# this step requires running with powershell in administrator mode. (Copy the three folders to c:\scripts and execute it)
#
# License: MIT Free to use, royalty free for ever, just thank me in the credits if you publish them.
#
# Sitefinity note, this assumes the theme is already registered with Sitefinity, if not, see their Website for more info
#
##############################################################################################################################
$TimeStamp = get-date -f MMddyyyy-hhmmss
$ThemeName = "Theme 1"
$MasterPageSource = "C:\temp\{myappthemes}\App_Master"
$MasterPageDestination = "C:\inetpub\wwwroot\{SiteFinityAppFolderinIIS}\App_Data\Sitefinity\WebsiteTemplates\{TemplateName}\App_Master"
$ThemeSourceFolder = "C:\temp\{myappthemes}"
$ThemeDestination = "C:\inetpub\wwwroot\{SiteFinityAppFolderinIIS}\App_Data\Sitefinity\WebsiteTemplates\{TemplateName}\App_Themes\$ThemeName"
$ThemeDestination = "C:\inetpub\wwwroot\{SiteFinityAppFolderinIIS}\App_Data\Sitefinity\WebsiteTemplates\{TemplateName}\App_Themes\$ThemeName"
echo "Preparing to Install Master Page from: $MasterPageSource"
echo "Installing Master Page to: $MasterPageDestination"
"Installing new Master Page"
Copy-Item -Path $MasterPageSource/*.* -Destination $MasterPageDestination -verbose -Force
echo ""
echo "Master Page Installation Successful!!"
#New-Item -ItemType directory -Path $ThemeCompressedArchivePath -Force
echo "Preparing to Install Theme '$ThemeName' from: $ThemeSourceFolder"
echo "Installing Theme '$ThemeName' to: $ThemeDestination"
#Copy-Item -Path (Get-Item -Path "$ThemeSourceFolder\*" -Exclude $excludes).FullName -Destination $ThemeDestination -Recurse -Force
echo ""
echo "Theme '$ThemeName' Installation Successful!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment