From 0df28b7f8289eb328a8400f57ca44bc4fd145503 Mon Sep 17 00:00:00 2001 From: Quinta <112334784+Quinta0@users.noreply.github.com> Date: Sun, 9 Jun 2024 01:33:52 +0200 Subject: [PATCH] Update install_obsidian.ps1 --- install_obsidian.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/install_obsidian.ps1 b/install_obsidian.ps1 index 84480d2..39e2894 100644 --- a/install_obsidian.ps1 +++ b/install_obsidian.ps1 @@ -1,5 +1,10 @@ # PowerShell script to install Obsidian and configure plugins on Windows +function Test-Administrator { + $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) + return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) +} + function Install-Obsidian-Windows { Write-Output "Installing Obsidian for Windows..." if (-Not (Get-Command choco -ErrorAction SilentlyContinue)) { @@ -66,6 +71,12 @@ function Install-Plugins { Write-Output "Plugins installed successfully." } +if (-Not (Test-Administrator)) { + Write-Output "This script needs to be run as an administrator. Re-launching with elevated privileges..." + Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs + exit +} + # Directly run Windows installation and plugin configuration Install-Obsidian-Windows Install-Plugins