jpsider/RestPS

Check for Administrative Permissions?

Closed this issue · 3 comments

Hi,

Decided to revisit this module for some tinkering and immediately hit issues with Invoke-DeployRestPS re: not running as admin (though the errors were not clear). Could we not implement a simple check to see if the script is running with elevated privileges? I'm not sure if this module is cross-platform though; the check I had in mind is Windows specific.

Thoughts?

Actually, the issue I'm having doesn't even appear related to administrative permissions. Following the instructions, installing RestPS from the gallery, then launching an administrative shell, importing the module and running Invoke-DeployRestPS generates many Copy-Item errors. The only files that end up in C:\RestPS are:

image

I'll see if I can figure out what's going on with this.

Just remember the Invoke-Deploy is just an example and not required. If you want to store your endpoint scripts and Json somewhere else, you can. Happy to help you along your journey.

Indeed. I've been working out of another directory but hit issues so wanted to try with a 'fresh' copy. The issue above was the fact that C:/RestPS already existed so the subfolders failed be created, which in turn caused the copy-item lines to break. I tested the following which seemed to be more flexible:

Write-Log -Logfile $Logfile -LogLevel $logLevel -MsgType INFO -Message "Invoke-DeployRestPS: Creating RestPS Directories if required."
if (!(Test-Path -Path $LocalDir)) { New-Item -Path "$LocalDir" -ItemType Directory }
if (!(Test-Path -Path "$LocalDir/bin")) { New-Item -Path "$LocalDir/bin" -ItemType Directory }
if (!(Test-Path -Path "$LocalDir/endpoints")) { New-Item -Path "$LocalDir/endpoints" -ItemType Directory }
if (!(Test-Path -Path "$LocalDir/endpoints/Logs")) { New-Item -Path "$LocalDir/endpoints/Logs" -ItemType Directory }
if (!(Test-Path -Path "$LocalDir/endpoints/GET")) { New-Item -Path "$LocalDir/endpoints/GET" -ItemType Directory }
if (!(Test-Path -Path "$LocalDir/endpoints/POST")) { New-Item -Path "$LocalDir/endpoints/POST" -ItemType Directory }
if (!(Test-Path -Path "$LocalDir/endpoints/PUT")) { New-Item -Path "$LocalDir/endpoints/PUT" -ItemType Directory }
if (!(Test-Path -Path "$LocalDir/endpoints/DELETE")) { New-Item -Path "$LocalDir/endpoints/DELETE" -ItemType Directory }   

I'll revert back to my original way of working and close this for now! Thanks.