From 5e0ca2e8adfa7d7afaccf69ac5aac28803cf8610 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Fri, 30 Oct 2020 15:06:26 +0100 Subject: [PATCH] Adds feature to open an Icinga Shell as other user --- doc/31-Changelog.md | 2 +- icinga-powershell-framework.psd1 | 3 ++- icinga-powershell-framework.psm1 | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index a1b895c..952cfec 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -15,7 +15,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#136](https://github.com/Icinga/icinga-powershell-framework/pull/136) Adds support to ignore empty check packages and return `Ok` instead of `Unknown` if `-IgnoreEmptyPackage` is set on `New-IcingaCheckPackage` * [#137](https://github.com/Icinga/icinga-powershell-framework/issues/137) Adds Cmdlet to compare a DateTime object with the current DateTime and return the offset as Integer in seconds - +* [#139](https://github.com/Icinga/icinga-powershell-framework/pull/139) Add Cmdlet `Start-IcingaShellAsUser` to open an Icinga Shell as different user for testing ### Bugfixes diff --git a/icinga-powershell-framework.psd1 b/icinga-powershell-framework.psd1 index 1d7c6d6..fb67b55 100644 --- a/icinga-powershell-framework.psd1 +++ b/icinga-powershell-framework.psd1 @@ -18,7 +18,8 @@ 'Get-IcingaCacheDir', 'Get-IcingaPowerShellConfigDir', 'Get-IcingaFrameworkRootPath', - 'Get-IcingaPowerShellModuleFile' + 'Get-IcingaPowerShellModuleFile', + 'Start-IcingaShellAsUser' ) CmdletsToExport = @() VariablesToExport = '*' diff --git a/icinga-powershell-framework.psm1 b/icinga-powershell-framework.psm1 index 07526c7..d7f933c 100644 --- a/icinga-powershell-framework.psm1 +++ b/icinga-powershell-framework.psm1 @@ -278,6 +278,7 @@ function Invoke-IcingaCommand() Write-Output '******************************************************'; Write-Output ([string]::Format('** Icinga PowerShell Framework {0}', $IcingaFrameworkData.PrivateData.Version)); Write-Output ([string]::Format('** Copyright {0}', $IcingaFrameworkData.Copyright)); + Write-Output ([string]::Format('** User environment {0}\{1}', $env:USERDOMAIN, $env:USERNAME)); Write-Output '******************************************************'; } @@ -310,5 +311,24 @@ function Invoke-IcingaCommand() } -Args $ScriptBlock, $PSScriptRoot, $IcingaFrameworkData.PrivateData.Version; } +function Start-IcingaShellAsUser() +{ + param ( + [string]$User = '' + ); + + Start-Process ` + -WorkingDirectory $PSHOME ` + -FilePath 'powershell.exe' ` + -Verb RunAs ` + -ArgumentList ( + [string]::Format( + "-Command `"Start-Process -FilePath `"powershell.exe`" -WorkingDirectory `"{0}`" -Credential (Get-Credential -UserName '{1}' -Message 'Please enter your credentials to open an Icinga Shell with') -ArgumentList icinga`"", + $PSHOME, + $User + ) + ); +} + Set-Alias icinga Invoke-IcingaCommand -Description "Execute Icinga Framework commands in a new PowerShell instance for testing or quick access to data"; Export-ModuleMember -Alias * -Function *;