Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

[UX] run build script without administrative privileges #77

Closed
lw-schick opened this issue Nov 9, 2016 · 2 comments
Closed

[UX] run build script without administrative privileges #77

lw-schick opened this issue Nov 9, 2016 · 2 comments

Comments

@lw-schick
Copy link
Collaborator

When I run the build function without administrative privileges, i get the following errors:

C:\git\PSGitLab [master ≡]> .\build.ps1
Install-Module : Zur Installation von Modulen in "C:\Program Files\WindowsPowerShell\Modules" sind Administratorrechte
erforderlich. Melden Sie sich unter einem Konto mit Administratorrechten beim Computer an, wiederholen Sie den
Vorgang, oder installieren Sie "C:\Users\leonhard.schick\Documents\WindowsPowerShell\Modules", indem Sie Ihrem Befehl
"-Scope CurrentUser" hinzufügen. Sie können auch versuchen, die Windows PowerShell-Sitzung mit erhöhten Rechten (Als
Administrator) auszuführen.
At C:\git\PSGitLab\build.ps1:39 char:17
+ ...               Install-Module -Name $ModuleName -Verbose:$false -Force
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-Module], ArgumentException
    + FullyQualifiedErrorId : InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser,Install-Module

Import-Module : The specified module 'BuildHelpers' was not loaded because no valid module file was found in any
module directory.
At C:\git\PSGitLab\build.ps1:40 char:17
+ ...             Import-Module -Name $ModuleName -Verbose:$false -Force -R ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (BuildHelpers:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Install-Module : Zur Installation von Modulen in "C:\Program Files\WindowsPowerShell\Modules" sind Administratorrechte
erforderlich. Melden Sie sich unter einem Konto mit Administratorrechten beim Computer an, wiederholen Sie den
Vorgang, oder installieren Sie "C:\Users\leonhard.schick\Documents\WindowsPowerShell\Modules", indem Sie Ihrem Befehl
"-Scope CurrentUser" hinzufügen. Sie können auch versuchen, die Windows PowerShell-Sitzung mit erhöhten Rechten (Als
Administrator) auszuführen.
At C:\git\PSGitLab\build.ps1:39 char:17
+ ...               Install-Module -Name $ModuleName -Verbose:$false -Force
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-Module], ArgumentException
    + FullyQualifiedErrorId : InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser,Install-Module

Import-Module : The specified module 'psake' was not loaded because no valid module file was found in any module
directory.
At C:\git\PSGitLab\build.ps1:40 char:17
+ ...             Import-Module -Name $ModuleName -Verbose:$false -Force -R ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (psake:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Install-Module : Zur Installation von Modulen in "C:\Program Files\WindowsPowerShell\Modules" sind Administratorrechte
erforderlich. Melden Sie sich unter einem Konto mit Administratorrechten beim Computer an, wiederholen Sie den
Vorgang, oder installieren Sie "C:\Users\leonhard.schick\Documents\WindowsPowerShell\Modules", indem Sie Ihrem Befehl
"-Scope CurrentUser" hinzufügen. Sie können auch versuchen, die Windows PowerShell-Sitzung mit erhöhten Rechten (Als
Administrator) auszuführen.
At C:\git\PSGitLab\build.ps1:39 char:17
+ ...               Install-Module -Name $ModuleName -Verbose:$false -Force
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-Module], ArgumentException
    + FullyQualifiedErrorId : InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser,Install-Module

Import-Module : The specified module 'Pester' was not loaded because no valid module file was found in any module
directory.
At C:\git\PSGitLab\build.ps1:40 char:17
+ ...             Import-Module -Name $ModuleName -Verbose:$false -Force -R ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (Pester:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Install-Module : Zur Installation von Modulen in "C:\Program Files\WindowsPowerShell\Modules" sind Administratorrechte
erforderlich. Melden Sie sich unter einem Konto mit Administratorrechten beim Computer an, wiederholen Sie den
Vorgang, oder installieren Sie "C:\Users\leonhard.schick\Documents\WindowsPowerShell\Modules", indem Sie Ihrem Befehl
"-Scope CurrentUser" hinzufügen. Sie können auch versuchen, die Windows PowerShell-Sitzung mit erhöhten Rechten (Als
Administrator) auszuführen.
At C:\git\PSGitLab\build.ps1:39 char:17
+ ...               Install-Module -Name $ModuleName -Verbose:$false -Force
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-Module], ArgumentException
    + FullyQualifiedErrorId : InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser,Install-Module

Import-Module : The specified module 'PSDeploy' was not loaded because no valid module file was found in any module
directory.
At C:\git\PSGitLab\build.ps1:40 char:17
+ ...             Import-Module -Name $ModuleName -Verbose:$false -Force -R ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (PSDeploy:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Install-Module : Zur Installation von Modulen in "C:\Program Files\WindowsPowerShell\Modules" sind Administratorrechte
erforderlich. Melden Sie sich unter einem Konto mit Administratorrechten beim Computer an, wiederholen Sie den
Vorgang, oder installieren Sie "C:\Users\leonhard.schick\Documents\WindowsPowerShell\Modules", indem Sie Ihrem Befehl
"-Scope CurrentUser" hinzufügen. Sie können auch versuchen, die Windows PowerShell-Sitzung mit erhöhten Rechten (Als
Administrator) auszuführen.
At C:\git\PSGitLab\build.ps1:39 char:17
+ ...               Install-Module -Name $ModuleName -Verbose:$false -Force
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-Module], ArgumentException
    + FullyQualifiedErrorId : InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser,Install-Module

Import-Module : The specified module 'PSScriptAnalyzer' was not loaded because no valid module file was found in any
module directory.
At C:\git\PSGitLab\build.ps1:40 char:17
+ ...             Import-Module -Name $ModuleName -Verbose:$false -Force -R ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (PSScriptAnalyzer:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Set-BuildEnvironment : The term 'Set-BuildEnvironment' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At C:\git\PSGitLab\build.ps1:51 char:1
+ Set-BuildEnvironment
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-BuildEnvironment:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Invoke-psake : The term 'Invoke-psake' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\git\PSGitLab\build.ps1:53 char:1
+ Invoke-psake -buildFile "$PSScriptRoot\psake.ps1" -taskList $Task -no ...
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Invoke-psake:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

It would be nice when the build script would check first if i have administrative privileges and if not throws a single error.

@ngetchell
Copy link
Owner

I'm migrating from PSake to Invoke-Build and will fix that. Thanks for letting me know.

@ngetchell
Copy link
Owner

An example fix:

if ( -not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] Administrator) ) {
    Write-Error "Build Script Requires Admin Rights"
    break;
}
Write-Host "Test"

With admin rights the example should write Test to the console. Without admin rights should show an error and without writing test to the console.

ngetchell added a commit that referenced this issue Nov 30, 2016
ngetchell added a commit that referenced this issue Nov 30, 2016
* Migrated from PSake to Invoke-Build

Fixes #77
Fixes #79

* Replacing psake with InvokeBuild

* bad build task name

* cleanup

* removing deploy
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants