Skip to content

Commit d51bcb6

Browse files
authored
Merge pull request #139 from Icinga/feature/add_cmdlet_to_open_shell_as_different_user
Feature: Add Cmdlet to open Icinga Shell as different user Add Cmdlet Start-IcingaShellAsUser to open an Icinga Shell as different user for testing
2 parents 82fb894 + 5e0ca2e commit d51bcb6

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

doc/31-Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1515

1616
* [#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`
1717
* [#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
18-
18+
* [#139](https://github.com/Icinga/icinga-powershell-framework/pull/139) Add Cmdlet `Start-IcingaShellAsUser` to open an Icinga Shell as different user for testing
1919

2020
### Bugfixes
2121

icinga-powershell-framework.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
'Get-IcingaCacheDir',
1919
'Get-IcingaPowerShellConfigDir',
2020
'Get-IcingaFrameworkRootPath',
21-
'Get-IcingaPowerShellModuleFile'
21+
'Get-IcingaPowerShellModuleFile',
22+
'Start-IcingaShellAsUser'
2223
)
2324
CmdletsToExport = @()
2425
VariablesToExport = '*'

icinga-powershell-framework.psm1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ function Invoke-IcingaCommand()
278278
Write-Output '******************************************************';
279279
Write-Output ([string]::Format('** Icinga PowerShell Framework {0}', $IcingaFrameworkData.PrivateData.Version));
280280
Write-Output ([string]::Format('** Copyright {0}', $IcingaFrameworkData.Copyright));
281+
Write-Output ([string]::Format('** User environment {0}\{1}', $env:USERDOMAIN, $env:USERNAME));
281282
Write-Output '******************************************************';
282283
}
283284

@@ -310,5 +311,24 @@ function Invoke-IcingaCommand()
310311
} -Args $ScriptBlock, $PSScriptRoot, $IcingaFrameworkData.PrivateData.Version;
311312
}
312313

314+
function Start-IcingaShellAsUser()
315+
{
316+
param (
317+
[string]$User = ''
318+
);
319+
320+
Start-Process `
321+
-WorkingDirectory $PSHOME `
322+
-FilePath 'powershell.exe' `
323+
-Verb RunAs `
324+
-ArgumentList (
325+
[string]::Format(
326+
"-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`"",
327+
$PSHOME,
328+
$User
329+
)
330+
);
331+
}
332+
313333
Set-Alias icinga Invoke-IcingaCommand -Description "Execute Icinga Framework commands in a new PowerShell instance for testing or quick access to data";
314334
Export-ModuleMember -Alias * -Function *;

0 commit comments

Comments
 (0)