Adds feature to open an Icinga Shell as other user

This commit is contained in:
Lord Hepipud 2020-10-30 15:06:26 +01:00
parent 82fb8945c4
commit 5e0ca2e8ad
3 changed files with 23 additions and 2 deletions

View file

@ -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

View file

@ -18,7 +18,8 @@
'Get-IcingaCacheDir',
'Get-IcingaPowerShellConfigDir',
'Get-IcingaFrameworkRootPath',
'Get-IcingaPowerShellModuleFile'
'Get-IcingaPowerShellModuleFile',
'Start-IcingaShellAsUser'
)
CmdletsToExport = @()
VariablesToExport = '*'

View file

@ -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 *;