mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
parent
e031e15bf5
commit
69ed78fa0a
1 changed files with 24 additions and 3 deletions
|
|
@ -265,24 +265,45 @@ function Invoke-IcingaCommand()
|
||||||
{
|
{
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
$ScriptBlock
|
$ScriptBlock,
|
||||||
|
[switch]$SkipHeader = $FALSE
|
||||||
);
|
);
|
||||||
|
|
||||||
powershell.exe -NoExit -Command {
|
powershell.exe -NoExit -Command {
|
||||||
$Script = $args[0]
|
$Script = $args[0];
|
||||||
|
[bool]$Header = $args[1].IsPresent;
|
||||||
|
$RootPath = $args[2];
|
||||||
|
|
||||||
|
# Load our Icinga Framework
|
||||||
Use-Icinga;
|
Use-Icinga;
|
||||||
|
|
||||||
|
# Set the location to the Icinga Framework module folder
|
||||||
|
Set-Location $RootPath;
|
||||||
|
|
||||||
|
# If we added a block to execute, do it right here and exit the shell
|
||||||
|
# with the last exit code of the command
|
||||||
if ([string]::IsNullOrEmpty($Script) -eq $FALSE) {
|
if ([string]::IsNullOrEmpty($Script) -eq $FALSE) {
|
||||||
Invoke-Command -ScriptBlock ([Scriptblock]::Create($Script));
|
Invoke-Command -ScriptBlock ([Scriptblock]::Create($Script));
|
||||||
exit $LASTEXITCODE;
|
exit $LASTEXITCODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Print a header informing our user that loaded the Icinga Framework with a specific
|
||||||
|
# version. We can also skip the header by using $SKipHeader
|
||||||
|
if ($null -eq $Header -Or $Header -eq $FALSE -Or -Not $Header) {
|
||||||
|
$FrameworkVersion = Get-IcingaPowerShellModuleVersion 'icinga-powershell-framework';
|
||||||
|
Write-IcingaConsolePlain '******************************************************';
|
||||||
|
Write-IcingaConsolePlain '** Icinga PowerShell Framework {0}' -Objects $FrameworkVersion;
|
||||||
|
Write-IcingaConsolePlain '** Copyright (c) 2020 Icinga GmbH | MIT';
|
||||||
|
Write-IcingaConsolePlain '******************************************************';
|
||||||
|
}
|
||||||
|
|
||||||
# Set our "path" to something different so we know that we loaded the Framework
|
# Set our "path" to something different so we know that we loaded the Framework
|
||||||
function prompt {
|
function prompt {
|
||||||
Write-Host -Object "icinga" -NoNewline;
|
Write-Host -Object "icinga" -NoNewline;
|
||||||
return "> "
|
return "> "
|
||||||
}
|
}
|
||||||
|
|
||||||
} -Args $ScriptBlock;
|
} -Args $ScriptBlock, $SkipHeader, $PSScriptRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Alias icinga Invoke-IcingaCommand -Description "Execute Icinga Framework commands in a new PowerShell instance for testing or quick access to data";
|
Set-Alias icinga Invoke-IcingaCommand -Description "Execute Icinga Framework commands in a new PowerShell instance for testing or quick access to data";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue