Start-JekyllBlogging.ps1


Description

Purpose

Starts a Jekyll blog server with administrative privileges if required.

Detailed Description

This function checks if the current user has administrative privileges. If so, it starts the Jekyll blog server. If not, it prompts the user to restart the script with administrative privileges.

Back to Top

Usage

Example 1

PS C:\> Start-JekyllBlogging

Starts the Jekyll blog server if the user has administrative privileges. Otherwise, prompts the user to restart the script with administrative privileges.

Back to Top

Notes

Author: Your Name Date: 2024-06-30

Back to Top


Script

<#
.SYNOPSIS
    Starts a Jekyll blog server with administrative privileges if required.

.DESCRIPTION
    This function checks if the current user has administrative privileges. If so, it starts the Jekyll blog server. 
    If not, it prompts the user to restart the script with administrative privileges.

.PARAMETER None
    This function does not take any parameters.

.EXAMPLE
    PS C:\> Start-JekyllBlogging
    Starts the Jekyll blog server if the user has administrative privileges. Otherwise, prompts the user to restart the script with administrative privileges.

.NOTES
    Author: Your Name
    Date: 2024-06-30
#>

function Start-JekyllBlogging {
	[CmdletBinding()]
	param ()

	# Function to check if the current user is an administrator
	function Test-IsAdmin {
		try {
			$currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
			return $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
		}
		catch {
			Write-Verbose "Error checking admin rights: $_"
			return $False
		}
	}

	# Verbose output indicating the start of the function
	Write-Verbose "Starting Jekyll Blogging function..."

	if (Test-IsAdmin) {
		Write-Verbose "User is an administrator. Starting Jekyll blog server..."
		New-JekyllBlogServer
	}
 else {
		Write-Warning "User is not an administrator. Prompting for administrative privileges..."
		Write-Verbose "Starting PowerShell with administrative privileges..."
		Start-Process -FilePath "pwsh.exe" -ArgumentList '-NoExit', '-Command', "& { $MyInvocation.Line }" -Verb runas -PassThru
	}

	# Verbose output indicating the end of the function
	Write-Verbose "Jekyll Blogging function completed."
}

# Define the New-JekyllBlogServer function for demonstration purposes
function New-JekyllBlogServer {
	Write-Host "Starting Jekyll blog server..."
	# Add your Jekyll blog server start commands here
}

# Example call to the function
# Start-JekyllBlogging -Verbose

Back to Top

Download

Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top