This information is for our users that have:
- many installations to deploy to their environment,
- know how to utilize RMM systems for distribution,
- understand PowerShell command syntax and variables.
Technical Support is unable to provide additional information about this process other than what is provided here.
This article utilizes a preconfigured and working Remote Monitoring and Management system that allows PowerShell variable declaration for users to deploy files, install the software, and schedule a preconfigured .NBK backup job using an existing Windows Account. (You can create this job on any system, just make sure it is set to Run as logged in user or uses an account that exists on all systems it is deployed to).
Required Files need to be configured to Deploy to a specific location before running the script (default %temp%\Deployment
See the "File Requirements" section of the README).
See information and an example about using cmd.exe to install here: [GUIDE] NovaBACKUP Client Deployment Method
Due to the error handling and variables involved, please open the .ps1 file contained in the attached zip file and review all of the variables before using the script
- The .ps1 deployment script can be found at the end of the article content. <here>
- The Script Contents are copied below the README section. <here>
Make sure to review the entire contents of the README included with the .ps1 script and understand the variables before using it.
README
# An example command is provided at the end of this documentation
####################
# PowerShell Notes #
####################
# Tab completion is your friend!
# Windows does not care about capitalization!
#
# You will need to change the script execution policy to test this script
# use "Help Set-ExecutionPolicy" to see the full information
# This will allow all .ps1 scripts to run
#
Set-ExecutionPolicy unrestricted
#
# For Services to be stopped or started, PowerShell must be "run as admin"
######################
# REQUIRED Parameter #
######################
# You MUST ALWAYS provide a Setup filename
# -SETUP_FILENAME "Setup-NB-BE.exe"
# Requirements:
# must not be null,
# must end with ".exe"
# specify as needed, default parameter is there as an example only
#####################
# FILE REQUIREMENTS #
#####################
# Before running this script
# there are one to three required files that must exist at
# "%temp%\Deployment"
# e.g. "C:\Users\Username\appdata\local\temp\Deployment"
#
# 1) The Setup File is always required
#
# * If -CLOUD_ENABLED is called: (you can specify the names for these as needed)
# 2) default: -CLOUD_PREMADE_FILENAME "My Cloud Backup.nbk"
# 3) (optional) -CLOUD_SCHEDULE_FILE "CloudSchedule.ini"
##################
# OUTPUT LOGGING #
##################
# There will be three log files always created for any installation using this script:
#
# All Logs will be created in the $SOURCEDIR directory specified
# default: "%temp%\Deployment"
#
# 1) Verbose logging created by the setup file
# $Setup_FILENAME.log
# example: "Setup-NB-BE.exe.log"
# 2) Logging performed by the deployment script
# $Setup_FILENAME_output.log
# example: "Setup-NB-BE.exe_output.log"
# 3) The "wrapper" installer log will be created in the default location
# %temp%\dotNetInstallerLog.txt
#
# (optional) -Transcript switch can be specified
# This will call Start-Transcript when the script starts
# $SETUP_FILENAME_transcript.txt
# example: "Setup-NB-BE.exe_transcript.txt"
###############
# OTHER NOTES #
###############
# The plan is to set some of the switches to $true for deployment, such as the CMon Agent Service (Management Server Service)
#
# These will "toggle" the switch to $true in the parameter block
# These require additional parameters, even if the script does not prompt you
# Look at the structure of the parameter block to see the groupings
# If you will be using NovaBACKUP Cloud, the default values specified for MANAGEMENT_SERVER_SERVICE should work
# -BRANDED
# -PRODUCT_COMPANY_NAME
# -PRODUCT_NAME
# -SERVICE_NAME
# -NSWEB_FILENAME
# -NSCMD_FILENAME
# -CLOUD_ENABLED
# -CLOUD_USERNAME
# -CLOUD_PASSWORD
# -CLOUD_JOB
# -MANAGEMENT_SERVER_SERVICE_START
# Switches (no value required, calling sets $true)
# -TRANSCRIPT
#
# If a premade NBK file does not exist, but was specified, the script will record a warning to the output log and skip scheduling the backup.
####################
# NBK SCRIPT NOTES #
####################
# * A Backup user account and hashed password is needed to be stored in the .NBK script, this cannot be plaintext
# - the software will not hash it for you on first run (unlike the cloud device)
# * The SessionName value will be pulled from the [device] section of the .NBK script to be displayed on the Schedule Tab of the software
# * Environment Variables can be declared in the script and will be replaced the first time the job runs (see help documentation)
#
# * If using default values in this deployment script, the Cloud Storage DeviceName is "Cloud"
# example [device] attribute in the .NBK script:
# [device]
# ...
# SesstionName=
# ...
# deviceUnit=Cloud
# deviceName=Cloud
# ...
####################
# Example commands #
####################
# This will perform the following:
# run the installer
# (telling it to start the CMon Agent Service),
# confirms the software was installed,
# specify "Nova" as the backup user account,
# copy default "My Cloud backup.nbk" (must end with .nbk) to UserScripts\Nova\Backup
# schedule the job using default settings (daily at 6PM)
# .\deployNS.ps1 -SETUP_FILENAME "Setup-NB-BE-19.5.1812.exe" -BACKUP_USER "Nova" -CLOUD_ENABLED -CLOUD_USERNAME "Nova" -CLOUD_PASSWORD "1234" -CLOUD_JOB -MANAGEMENT_SERVER_SERVICE_START
# This will do the same as the previous command, but will change the source file directory to the current directory the script is ran from.
# .\deployNS.ps1 -SETUP_FILENAME "Setup-NB-BE-19.5.1812.exe" -SOURCEDIR $PSScriptRoot -BACKUP_USER "Nova" -CLOUD_ENABLED -CLOUD_USERNAME "Nova" -CLOUD_PASSWORD "1234" -CLOUD_JOB -MANAGEMENT_SERVER_SERVICE_START
# Extremely Basic command accepting all defaults
# default for -BACKUP_USER is "SYSTEM"
# default source file location is "C:\Users\Username\appdata\local\temp\Deployment"
.\deployNS.ps1 -SETUP_FILENAME "Setup-NB-BE-19.5.1812.exe"
Script Contents
#Requires -RunAsAdministrator
param(
[Parameter(Mandatory = $true)][ValidatePattern("(.exe)$")][ValidateNotNull()]
[string]$SETUP_FILENAME = "Setup-NB-BE-19.5.1812.exe",# you must still provide a value when calling this script, this is an example filename
[string]$SOURCEDIR = "$env:TEMP\Deployment",
[string]$BACKUP_USER = "SYSTEM",
[string]$LICENSE_NAME = "Name",
[string]$LICENSE_COMPANY_NAME = "Company",
[ValidatePattern("^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$")]
[mailaddress]$LICENSE_EMAIL_ADDRESS = "noreply@novabackup.com",
[switch]$BRANDED = $false,# if custom branded installation then these are required
[string]$PRODUCT_COMPANY_NAME,
[string]$PRODUCT_NAME,
[string]$SERVICE_NAME,
[string]$NSWEB_FILENAME,
[string]$NSCMD_FILENAME,
[switch]$CLOUD_ENABLED = $false,# if using Cloud Storage (Create Cloud Device)
[string]$CLOUD_USERNAME,
[string]$CLOUD_PASSWORD,
[string]$CLOUD_BACKUPSERVER = "backup.online-backup.com",
[int]$CLOUD_BACKUPSERVER_PORT = 308,
[switch]$CLOUD_JOB = $false,# if scheduling a premade cloud backup job
[ValidatePattern("(.nbk)$")]
[string]$CLOUD_JOB_FILENAME = "My Cloud Backup.nbk",
[ValidatePattern("(.ini)$")]
[string]$CLOUD_SCHEDULE_FILENAME = "CloudSchedule.ini",
[ValidateSet('once','minute','hourly','daily','weekly','monthly')]
[string]$CLOUD_SCHEDULE_TYPE = "daily",
[ValidatePattern("^(2[0-3]|[0,1][0-9])$")]
[string]$CLOUD_JOB_HOUR = "18",# 00-23
[ValidatePattern("^([0-5][0-9])$")]
[string]$CLOUD_JOB_MIN = "30",# 00-59
[switch]$MANAGEMENT_SERVER_SERVICE_START = $false,# starts CMon Agent Service
[string]$MANAGEMENT_SERVER_PUBLIC_SERVER_ADDRESS = "portal.online-backup.com",
[int]$MANAGEMENT_SERVER_PORT = 4502,
[switch]$TRANSCRIPT = $false
)
function Write-Log {
[CmdletBinding()]
param(
[Parameter(Mandatory = $False)]
[ValidateSet("INFO","WARN","ERROR","FATAL","DEBUG")]
[string]$Level = "INFO",
[Parameter(Mandatory = $True)]
[string]$Message,
[Parameter(Mandatory = $False)]
[string]$logfile
)
$Stamp = (Get-Date).ToString("yyyy/MM/dd HH:mm:ss")
$Line = "$Stamp $Level $Message"
if ($logfile) {
Add-Content $logfile -Value $Line -Passthru
}
else {
Write-Output $Line
}
}
#################################
# SECTION Variable Construction #
#################################
# Logging Information
$SETUP_LOG_FILENAME `
= $SETUP_FILENAME + ".log"
$SETUP_LOG_PATH `
= Join-Path -Path $SOURCEDIR -ChildPath $SETUP_LOG_FILENAME
$OUTPUT_LOG_FILENAME `
= $SETUP_FILENAME + "_output.log"
$OUTPUT_LOG_PATH `
= Join-Path -Path $SOURCEDIR -ChildPath $OUTPUT_LOG_FILENAME
if ($TRANSCRIPT) {
$TRANSCRIPT_FILENAME = $SETUP_FILENAME + "_transcript.txt"
$TRANSCRIPT_PATH = Join-Path -Path $SOURCEDIR -ChildPath $TRANSCRIPT_FILENAME
Start-Transcript -Path $TRANSCRIPT_PATH -Append -Force -IncludeInvocationHeader
}
# CHECK SOURCE DIR
if (Test-Path ($SOURCEDIR -eq $false)) { # Source Directory Not Found
$OUTPUT_LOG_PATH `
= Join-Path -Path $PSScriptRoot -ChildPath $OUTPUT_LOG_FILENAME
Write-Log -Level "FATAL" -Message "No Files Found at $SOURCEDIR" -logfile $OUTPUT_LOG_PATH
Write-Log -Level "INFO" -Message "`t HINT: You can change the Source Directory using the -SOURCEDIR Parameter." -logfile $OUTPUT_LOG_PATH
throw "No Files Found at $SOURCEDIR `n HINT: You can change the Source Directory using the -SOURCEDIR Parameter."
} else {
# CHECK SETUP FILE SOURCE
$SETUP_FILE_SOURCE_PATH `
= Join-Path -Path $SOURCEDIR -ChildPath $SETUP_FILENAME
if (Test-Path ($SETUP_FILE_SOURCE_PATH -eq $false)) { # Setup File Not Found
Write-Log -Level "FATAL" -Message "Setup File Not Found at $SETUP_FILE_SOURCE_PATH" -logfile $OUTPUT_LOG_PATH
throw "Setup File Not Found at $SETUP_FILE_SOURCE_PATH"
} else {
# Is this a custom installer?
if (!$BRANDED) { # if $BRANDED = $false then set default values
$PRODUCT_COMPANY_NAME `
= "NovaStor"
$PRODUCT_NAME `
= "NovaBACKUP"
$SERVICE_NAME `
= "nsService"
$NSWEB_FILENAME `
= "nsWeb.ini"
$NSCMD_FILENAME `
= "nsCmd.exe"
}
# Set installation paths
$PROGRAMDATA_PATH `
= "$env:programdata\$PRODUCT_COMPANY_NAME\$PRODUCT_COMPANY_NAME $PRODUCT_NAME"
$PROGRAMFILES_PATH `
= "$env:programfiles\$PRODUCT_COMPANY_NAME\$PRODUCT_COMPANY_NAME $PRODUCT_NAME"
# Is this a Cloud Account?
if ($CLOUD_ENABLED) {
$NSWEB_PATH `
= Join-Path -Path $PROGRAMDATA_PATH -ChildPath "Profiles\$NSWEB_FILENAME" # default nsweb.ini path %programdata%\NovaStor\NovaStor NovaBACKUP\Profiles\nsweb.ini
$NSWEB_DEVICE_CONTENT `
= @"
[Device0]
BackupServer=$CLOUD_BACKUPSERVER
ServerPort=$CLOUD_BACKUPSERVER_PORT
UserName=$CLOUD_USERNAME
Password=$CLOUD_PASSWORD
deviceName=Cloud
"@
}
# Is there a Premade Cloud Job being scheduled?
if ($CLOUD_JOB) {
$CLOUD_NBK_PREMADE_PATH `
= Join-Path -Path $SOURCEDIR -ChildPath $CLOUD_JOB_FILENAME
if (Test-Path ($CLOUD_NBK_PREMADE_PATH -eq $false)) {
Write-Log -Level "WARN" -Message "No Premade NBK File Found. Job will NOT be scheduled." -logfile $OUTPUT_LOG_PATH
$SCHEDULE_SKIPPED = $true
} else {
$SCHEDULE_SKIPPED = $false
$NBK_DEST_PATH `
= Join-Path -Path $PROGRAMDATA_PATH -ChildPath "UserScripts\$BACKUP_USER\Backup" # default nbk backup file location %programdata%\NovaStor\NovaStor NovaBACKUP\UserScripts\SYSTEM\Backup\My Cloud Backup.nbk
$CLOUD_SCHEDULE_START_TIME = $CLOUD_JOB_HOUR + "-" + $CLOUD_JOB_MIN + "-00" # 18-30-00
$CLOUD_SCHEDULE_START_DATE = [datetime]::Today.ToString("MM-dd-yyyy") # 08-17-2020
$NSCMD_PATH = Join-Path -Path $PROGRAMFILES_PATH -ChildPath $NSCMD_FILENAME
$NBK_SCHEDULE_SOURCE_PATH = Join-Path -Path $SOURCEDIR -ChildPath $CLOUD_SCHEDULE_FILENAME
$CLOUD_SCHEDULE_NAME = Select-String -LiteralPath $CLOUD_NBK_PREMADE_PATH -Pattern "ScheduleName=" -SimpleMatch
$CLOUD_SCHEDULE_NAME = $CLOUD_SCHEDULE_NAME -split "=",-1
$CLOUD_SCHEDULE_NAME = $CLOUD_SCHEDULE_NAME[-1]
$NBK_SCHEDULE_CONTENT `
= @"
ScheduleName=<$CLOUD_SCHEDULE_NAME>
ScheduleType=<$CLOUD_SCHEDULE_TYPE>
StartDate=<$CLOUD_SCHEDULE_START_DATE>
StartTime=<$CLOUD_SCHEDULE_START_TIME>
"@
}
}
# Management Server Info
if ($MANAGEMENT_SERVER_SERVICE_START) {
$MANAGEMENT_SERVER_AGENT_SERVICE_STARTMODE `
= "Automatic"
$START_MANAGEMENT_SERVER_AGENT_SERVICE `
= 1
}
# END SECTION Variable Constructions
########################################
# SECTION Display Some Variable Values #
########################################
# Write Variable Values to the prompt
Write-Log -Level "INFO" -Message "Setup File:`t`t $SETUP_FILE_SOURCE_PATH" -logfile $OUTPUT_LOG_PATH
if (Test-Path ($SETUP_FILE_SOURCE_PATH -eq $false)) {
Write-Log -Level "FATAL" -Message "Setup File Not Found at $SETUP_FILE_SOURCE_PATH" -logfile $OUTPUT_LOG_PATH
throw "Setup File Not Found at $SETUP_FILE_SOURCE_PATH"
}
Write-Log -Level "INFO" -Message "Backup User:`t`t $BACKUP_USER" -logfile $OUTPUT_LOG_PATH
if ($CLOUD_ENABLED) {
Write-Log -Level "INFO" -Message "Cloud Account info: " -logfile $OUTPUT_LOG_PATH
Write-Log -Level "INFO" -Message "`t Cloud User: $CLOUD_USERNAME" -logfile $OUTPUT_LOG_PATH
if ($CLOUD_PASSWORD) { Write-Log -Level "INFO" -Message "`t A Cloud Password was provided" -logfile $OUTPUT_LOG_PATH }
}
Write-Log -Level "INFO" -Message "Log Locations: " -logfile $OUTPUT_LOG_PATH
Write-Log -Level "INFO" -Message "`t Setup Wrapper Path:`t`t $env:TEMP\dotNetInstallerLog.txt" -logfile $OUTPUT_LOG_PATH
Write-Log -Level "INFO" -Message "`t Setup Log Path:`t`t $SETUP_LOG_PATH" -logfile $OUTPUT_LOG_PATH
if ($TRANSCRIPT) { Write-Log -Level "INFO" -Message "`t`t Transcript Path:`t $TRANSCRIPT_PATH" -logfile $OUTPUT_LOG_PATH }
Write-Log -Level "INFO" -Message "`t Script Output Log:`t`t $OUTPUT_LOG_PATH" -logfile $OUTPUT_LOG_PATH
# END SECTION Display Some Variable Values
############################################################
# SECTION Store the ArgumentList and ComponentArgs 'props' #
############################################################
[string]$instArgumentList
# start filling the arguments
$instARGS = "/q /noreboot /Log /ComponentArgs `"Backup Client`":`"/q /log $SETUP_LOG_PATH "
# populate the 'instProps array'
# IMPORTANT: Make sure the first value has a space at the beginning for joining later
$instProps = @()
$instProps += " /prop REBOOT=ReallySuppress"
$instProps += "/prop LICENSE_NAME=$LICENSE_NAME"
$instProps += "/prop LICENSE_COMPANY_NAME=$LICENSE_COMPANY_NAME"
$instProps += "/prop LICENSE_EMAIL_ADDRESS=$LICENSE_EMAIL_ADDRESS"
if ($MANAGEMENT_SERVER_SERVICE_START) {
$instProps += "/prop MANAGEMENT_SERVER_PUBLIC_SERVER_ADDRESS=$MANAGEMENT_SERVER_PUBLIC_SERVER_ADDRESS"
$instProps += "/prop MANAGEMENT_SERVER_PORT=$MANAGEMENT_SERVER_PORT"
$instProps += "/prop MANAGEMENT_SERVER_AGENT_SERVICE_STARTMODE=$MANAGEMENT_SERVER_AGENT_SERVICE_STARTMODE"
$instProps += "/prop START_MANAGEMENT_SERVER_AGENT_SERVICE=$START_MANAGEMENT_SERVER_AGENT_SERVICE"
}
# join ArgumentList and /props and close the statement
$instArgumentList = $instARGS + ($instProps -join ' ') + "`""
# END SECTION ArgumentList and ComponentArgs
###########################
# SECTION Setup Installer #
###########################
# START THE INSTALLATION
# Example call
# Start-Process -FilePath "$env:temp\Deployment\Setup-NB-BE-19.5.1812.exe" -ArgumentList "/q /noreboot /Log /ComponentArgs `"Backup Client`":`"/q /log c:\NovaBACKUP_setuplog.txt /prop REBOOT=ReallySuppress /prop LICENSE_NAME=Name /prop LICENSE_COMPANY_NAME=Company /prop LICENSE_EMAIL_ADDRESS=noreply@novabackup.com /prop MANAGEMENT_SERVER_PUBLIC_SERVER_ADDRESS=portal.online-backup.com /prop MANAGEMENT_SERVER_PORT=4502 /prop MANAGEMENT_SERVER_AGENT_SERVICE_STARTMODE=Automatic /prop START_MANAGEMENT_SERVER_AGENT_SERVICE=1`"" -Wait
Write-Log -Level "INFO" -Message "Beginning Installation." -logfile $OUTPUT_LOG_PATH
Start-Process -FilePath $SETUP_FILE_SOURCE_PATH -ArgumentList $instArgumentList -Wait
Write-Log -Level "INFO" -Message "Installation completed." -logfile $OUTPUT_LOG_PATH
# END SECTION Setup Installer
##############################
# SECTION Installation Check #
##############################
Write-Log -Level "INFO" -Message "Confirming Installation Status..." -logfile $OUTPUT_LOG_PATH
<# information from "setup installer.txt"
# Determine the Installation status (Success/Fail)
# The setup installer detects if NovaBACKUP is already installed by checking one or more of the following registry keys:
# 1. By the upgrade code
# HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes\913BD93868D1FEB48AC9840997D3B98A
# HKEY_CLASSES_ROOT\Installer\UpgradeCodes\913BD93868D1FEB48AC9840997D3B98A
# 2. By the uninstall registry entry
# On a 32-bit operating system:
# HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NovaBACKUP
# On a 64-bit operating system:
# HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\NovaBACKUP
# 3. By the product code
# Whichever key has "NovaBACKUP" set as the DisplayName value under the following registry key:
# HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
#
# If any of those keys exist, the setup installer indicates that NovaBACKUP is installed.
#>
[int]$InstChk = 0
if (Test-Path "Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes\913BD93868D1FEB48AC9840997D3B98A") { $InstChk++ }
if (Test-Path "Registry::HKEY_CLASSES_ROOT\Installer\UpgradeCodes\913BD93868D1FEB48AC9840997D3B98A") { $InstChk++ }
if (Test-Path "Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$PRODUCT_NAME") { $InstChk++ }
if (Test-Path "Registry::HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$PRODUCT_NAME") { $InstChk++ }
if (Get-Process -Name $SERVICE_NAME) { $InstChk++ }
# If InstChk was incremented, the software was detected in the Registry
if ($InstChk -gt 0) {
if (Test-Path "Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$PRODUCT_NAME") {
$InstVer = Get-ItemPropertyValue "Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$PRODUCT_NAME" "DisplayVersion"
Write-Log -Level "INFO" -Message "$PRODUCT_NAME $InstVer is installed." -logfile $OUTPUT_LOG_PATH
}
if (Test-Path "Registry::HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$PRODUCT_NAME") {
$InstVer = Get-ItemPropertyValue "Registry::HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$PRODUCT_NAME" "DisplayVersion"
Write-Log -Level "INFO" -Message "$PRODUCT_NAME $InstVer is installed." -logfile $OUTPUT_LOG_PATH
}
} else {
Write-Log -Level ERROR -Message "$PRODUCT_NAME is NOT Installed." -logfile $OUTPUT_LOG_PATH
Write-Log -Level ERROR -Message "`tSearch $SETUP_LOG_PATH for 'Return value 3' for the installation error." -logfile $OUTPUT_LOG_PATH
# parse the log file and include the preceeding 6 and following 0 lines
$string = "Return Value 3"
$context = Get-Content $SETUP_LOG_PATH | Select-String $string -Context 6,0 -SimpleMatch
Write-Log -Level ERROR -Message "`t Context: `n`t $context" -logfile $OUTPUT_LOG_PATH
throw "Installation of $SETUP_FILENAME failed. Context: $context"
}
# report the install status message from the verbose log in all cases
$string = "Windows Installer installed the product"
Get-Content $SETUP_LOG_PATH | Select-String $string -Context 3,0 -SimpleMatch
Write-Log -Level "INFO" -Message "$string" -logfile $OUTPUT_LOG_PATH
# Alternate method to verify installation - (takes a long time to poll WmiObject)
# don't use if possible
# Get-WmiObject -Class Win32_Product | where vendor -eq NovaStor | select Name, Version | Out-File -Append $OUTPUT
# END SECTION Installation Check
#########################
# SECTION CLOUD_ENABLED #
#########################
if ($CLOUD_ENABLED) {
# STOP Service
Write-Log -Level "INFO" -Message "Stopping $SERVICE_NAME to apply config changes." -logfile $OUTPUT_LOG_PATH
Stop-Service -Name $SERVICE_NAME
Start-Sleep -s 5
$STATUS = Get-Service -Name $SERVICE_NAME
# append nsweb.ini with required device information incl $CLOUD_USERNAME and $CLOUD_PASSWORD
# nsweb.ini will fill in the other default device information and hash the password on service restart
Write-Log -Level "INFO" -Message "Creating Cloud Device" -logfile $OUTPUT_LOG_PATH
Add-Content -Path $NSWEB_PATH -Value $NSWEB_DEVICE_CONTENT
if ($CLOUD_JOB -and !$SCHEDULE_SKIPPED) { # if Cloud_Job provided and found ($SCHEDULE_SKIPPED = $false)
# Copy premade .NBK script to appropriate location from where deployed originally
Copy-Item -Path $CLOUD_NBK_PREMADE_PATH -Destination $NBK_DEST_PATH
# Schedule .NBK job
if ((Test-Path $NBK_SCHEDULE_SOURCE_PATH) -eq $false) { # if CloudSchedule.ini does NOT exist then create one
Write-Log -Level "INFO" -Message "Creating schedule" -logfile $OUTPUT_LOG_PATH
New-Item -Path $NBK_SCHEDULE_SOURCE_PATH -ItemType "file" -Value "$NBK_SCHEDULE_CONTENT"
}
Write-Log -Level "INFO" -Message "Using $CLOUD_SCHEDULE_FILENAME to Schedule $NBK_DEST_PATH" -logfile $OUTPUT_LOG_PATH
# call nscmd.exe and schedule the job
# nbkcmd.exe -s c:\backupplan\natesbackup.nbk -t c:\backupplan\natesbackupschedule.ini
Write-Log -Level "INFO" -Message "Scheduling $CLOUD_JOB_FILENAME" -logfile $OUTPUT_LOG_PATH
Start-Process -FilePath $NSCMD_PATH -ArgumentList "-s $NBK_DEST_PATH -t $NBK_SCHEDULE_SOURCE_PATH" -Wait
} elseif ($SCHEDULE_SKIPPED) { # if $SCHEDULE_SKIPPED = $true
Write-Log -Level "WARN" -Message "No Premade NBK File. Job was NOT scheduled." -logfile $OUTPUT_LOG_PATH
}
# Restart service and get the status
Write-Log -Level "INFO" -Message "Starting $SERVICE_NAME to apply config changes." -logfile $OUTPUT_LOG_PATH
Start-Service -Name $SERVICE_NAME
Start-Sleep -s 5
$STATUS = Get-Service -Name $SERVICE_NAME
} # END CLOUD_ENABLED
} # END SETUP FILE NOT FOUND
} # END Source DIR NOT FOUND
Write-Log -Level "INFO" -Message "Deployment Script execution completed" -logfile $OUTPUT_LOG_PATH
###########################
# SECTION Stop-Transcript #
###########################
if ($TRANSCRIPT) { Stop-Transcript }
#END SECTION Stop-Transcript