# generate all-in-one install script, more suitable for running on the endpoints $cmdMagic = @' # 2> nul & powershell.exe -ExecutionPolicy Bypass -NoProfile -Command "[scriptblock]::Create((Get-Content -LiteralPath '%~f0' -Raw)).Invoke()" #& EXIT /B '@ pushd $PSScriptRoot $sourcefile = 'Install-ZabbixAgent2.Template.ps1' #Join-Path aio-installer if (Test-path (Join-Path aio-installer $sourcefile)) { $gi = Get-Item (Join-Path aio-installer $sourcefile) Write-Verbose ('Template exists at {0}' -f $sourcefile) } else { if (Test-Path (Join-Path Templates $sourcefile)) { try { Copy-Item -Path (Join-Path Templates $sourcefile) -Destination (Join-Path . aio-installer) -ErrorAction Stop $gi = Get-Item (Join-Path aio-installer $sourcefile) } catch { throw ("Couldn't copy the template {0} to current dir, aborting" -f (Join-Path Templates $sourcefile)) } } } $c = Get-Content $gi.FullName $n = @() $regex = '^\s*#include#\.\s+?(?.+)$' foreach ($l in $c) { if ($l -match $regex) { Get-Content $Matches['includePath'] | % { $n += $_ } } else { $n += $l } } $n | Set-Content (Join-Path aio-installer ($sourcefile -replace '\.Template\.ps1','.AllInOne.ps1')) @($cmdMagic) + $n | Set-Content (Join-Path aio-installer ($sourcefile -replace '\.Template\.ps1','.AllInOne.cmd')) popd