Skip to content

Commit

Permalink
Merge pull request #2 from UniverseCitiz3n/rc1
Browse files Browse the repository at this point in the history
Rc1
  • Loading branch information
UniverseCitiz3n authored Jan 18, 2021
2 parents 6203b6e + c5f6528 commit b403eb1
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 108 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/psgallery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test PowerShell on Windows
on: push

jobs:
tests:
name: Pester test and ScriptAnalyzer
runs-on: windows-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Perform a Pester test from the Tests.ps1 file
shell: pwsh
run: |
Invoke-Pester .\tests\Unit.Tests.ps1 -Passthru
- name: Install PSScriptAnalyzer module
if: success()
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -ErrorAction Stop
- name: Lint with PSScriptAnalyzer
if: success()
shell: pwsh
run: |
Invoke-ScriptAnalyzer -Path .\Intune-App-Sandbox\Public\*.ps1 -Recurse -Outvariable issues -ExcludeRule PSAvoidUsingWriteHost,PSUseShouldProcessForStateChangingFunctions
$errors = $issues.Where({$_.Severity -eq 'Error'})
$warnings = $issues.Where({$_.Severity -eq 'Warning'})
if ($errors) {
Write-Error "There were $($errors.Count) errors and $($warnings.Count) warnings total." -ErrorAction Stop
} else {
Write-Output "There were $($errors.Count) errors and $($warnings.Count) warnings total."
}
108 changes: 0 additions & 108 deletions Intune-App-Sandbox/Add-SandboxShell.ps1

This file was deleted.

File renamed without changes.
Binary file added Intune-App-Sandbox/Intune-App-Sandbox.psd1
Binary file not shown.
11 changes: 11 additions & 0 deletions Intune-App-Sandbox/Intune-App-Sandbox.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$Public = @(Get-ChildItem -Recurse -Path $PSScriptRoot\Public\*.ps1 | Where-Object { $_ -notmatch '\.Examples.ps1' })

foreach ($import in $Public) {
try {
. $import.fullname
} catch {
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}

Export-ModuleMember -Function $Public.Basename
108 changes: 108 additions & 0 deletions Intune-App-Sandbox/Public/Add-SandboxShell.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
function Add-SandboxShell {
<#
.SYNOPSIS
This tool is for testing Powershell Script which is packed using Win32 Content Prep Tool for installing software using Win32 Deployment profile in Intune.
.DESCRIPTION
This is a configuration script which will create
folder at location C:\Sandbox for storing binaries, icons, scripts and wsb files.
It also adds options to system context menu for packing intuewin and testing
such package.
Such package should contain Install-Script.ps1 and all the neccessary binaries, executables.
To correctly create intunewin package, please name parent folder as the same as *.ps1 script within!
.NOTES
© 2021 Maciej Horbacz
#>

If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Output "This function needs to be run As Admin"
Break
}
Clear-Host
Write-Host 'Thanks for using this tool!' -ForegroundColor Green
Write-Host 'Starting configuration process...' -ForegroundColor Yellow
Write-Host 'Checking for operating folder...' -ForegroundColor Yellow -NoNewline
$SandboxOperatingFolder = 'C:\SandboxEnvironment\bin'
[string] $module = (Get-Command -Name $MyInvocation.MyCommand -All).Source
$PathModule = (Get-Module -Name $module.Trim() | Select-Object ModuleBase -First 1).ModuleBase
If (!(Test-Path -Path $SandboxOperatingFolder -PathType Container)) {
Start-Sleep 2
Write-Host 'Not found!' -ForegroundColor Red
Write-Host 'Adding operating folder...' -ForegroundColor Yellow
New-Item -Path $SandboxOperatingFolder -ItemType Directory | Out-Null
Start-Sleep 1
Write-Host 'Folder found!' -ForegroundColor Green
Write-Host "Copying crucial files to $SandboxOperatingFolder" -ForegroundColor Yellow
Copy-Item -Path $PathModule\Configuration\* -Recurse -Destination $SandboxOperatingFolder -Force
Write-Host "Copying helpers files to C:\SandboxEnvironment" -ForegroundColor Yellow
Copy-Item -Path $PathModule\Helpers\* -Recurse -Destination 'C:\SandboxEnvironment' -Force
}
Write-Host "
Contex menu options:
1 - Only 'Run test in Sandbox'
2 - Only 'Pack with IntunewinUtil'
3 - Both
" -ForegroundColor Yellow
Write-Host 'Please specify your choice: ' -ForegroundColor Yellow -NoNewline
$Option = Read-Host
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR_SD | Out-Null
switch ($Option) {
1 {
If (!(Test-Path -Path 'HKCR_SD:\.intunewin\Shell\Run test in Sandbox\Command')) {
Write-Host 'Context menu item not present.' -ForegroundColor Green
New-Item -Path HKCR_SD:\ -Name '.intunewin'
New-Item -Path HKCR_SD:\.intunewin -Name 'Shell'
Set-Item -Path HKCR_SD:\.intunewin\Shell -Value Open
New-Item -Path HKCR_SD:\.intunewin\Shell -Name 'Run test in Sandbox'
New-ItemProperty -Path 'HKCR_SD:\.intunewin\Shell\Run test in Sandbox' -Name icon -PropertyType 'String' -Value "$SandboxOperatingFolder\sandbox.ico"
New-Item -Path 'HKCR_SD:\.intunewin\Shell\Run test in Sandbox' -Name 'Command'
Set-Item -Path 'HKCR_SD:\.intunewin\Shell\Run test in Sandbox\Command' -Value "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -command $SandboxOperatingFolder\Invoke-Test.ps1 -PackagePath `"%V`""
} else {
Write-Host 'Context menu item already present!' -ForegroundColor Yellow
}
}
2 {
If (!(Test-Path -Path 'HKCR_SD:\Directory\Shell\Pack with IntunewinUtil\Command')) {
Write-Host 'Context menu item not present.' -ForegroundColor Green
New-Item -Path HKCR_SD:\Directory\Shell\ -Name 'Pack with IntunewinUtil'
New-ItemProperty -Path 'HKCR_SD:\Directory\Shell\Pack with IntunewinUtil' -Name icon -PropertyType 'String' -Value "$SandboxOperatingFolder\intunewin-Box-icon.ico"
New-Item -Path 'HKCR_SD:\Directory\Shell\Pack with IntunewinUtil' -Name 'Command'
Set-Item -Path 'HKCR_SD:\Directory\Shell\Pack with IntunewinUtil\Command' -Value "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file $SandboxOperatingFolder\Invoke-IntunewinUtil.ps1 -PackagePath `"%V`""
} else {
Write-Host 'Context menu item already present!' -ForegroundColor Yellow
}
}
3 {
If (!(Test-Path -Path 'HKCR_SD:\.intunewin\Shell\Run test in Sandbox\Command')) {
Write-Host 'Context menu item not present.' -ForegroundColor Green
New-Item -Path HKCR_SD:\ -Name '.intunewin'
New-Item -Path HKCR_SD:\.intunewin -Name 'Shell'
Set-Item -Path HKCR_SD:\.intunewin\Shell -Value Open
New-Item -Path HKCR_SD:\.intunewin\Shell -Name 'Run test in Sandbox'
New-ItemProperty -Path 'HKCR_SD:\.intunewin\Shell\Run test in Sandbox' -Name icon -PropertyType 'String' -Value "$SandboxOperatingFolder\sandbox.ico"
New-Item -Path 'HKCR_SD:\.intunewin\Shell\Run test in Sandbox' -Name 'Command'
Set-Item -Path 'HKCR_SD:\.intunewin\Shell\Run test in Sandbox\Command' -Value "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -command $SandboxOperatingFolder\Invoke-Test.ps1 -PackagePath `"%V`""
} else {
Write-Host 'Context menu item already present!' -ForegroundColor Yellow
}
If (!(Test-Path -Path 'HKCR_SD:\Directory\Shell\Pack with IntunewinUtil\Command')) {
Write-Host 'Context menu item not present.' -ForegroundColor Green
New-Item -Path HKCR_SD:\Directory\Shell\ -Name 'Pack with IntunewinUtil'
New-ItemProperty -Path 'HKCR_SD:\Directory\Shell\Pack with IntunewinUtil' -Name icon -PropertyType 'String' -Value "$SandboxOperatingFolder\intunewin-Box-icon.ico"
New-Item -Path 'HKCR_SD:\Directory\Shell\Pack with IntunewinUtil' -Name 'Command'
Set-Item -Path 'HKCR_SD:\Directory\Shell\Pack with IntunewinUtil\Command' -Value "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file $SandboxOperatingFolder\Invoke-IntunewinUtil.ps1 -PackagePath `"%V`""
} else {
Write-Host 'Context menu item already present!' -ForegroundColor Yellow
}
}
Default {
Write-Host 'Wrong option! Bye...' -ForegroundColor Red
Break
}
}
Write-Host 'All done!' -ForegroundColor Green
Pause
}
37 changes: 37 additions & 0 deletions Intune-App-Sandbox/Public/Update-SandboxShell.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function Update-SandboxShell {
<#
.SYNOPSIS
This tool is for testing Powershell Script which is packed using Win32 Content Prep Tool for installing software using Win32 Deployment profile in Intune.
.DESCRIPTION
This is a configuration script which will update
folder at location C:\Sandbox for storing binaries, icons, scripts and wsb files.
Such package should contain Install-Script.ps1 and all the neccessary binaries, executables.
To correctly create intunewin package, please name parent folder as the same as *.ps1 script within!
.NOTES
© 2021 Maciej Horbacz
#>

If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Output "This function needs to be run As Admin"
Break
}
Clear-Host
Write-Host 'Thanks for using this tool!' -ForegroundColor Green
Write-Host 'Starting update process...' -ForegroundColor Yellow
Write-Host 'Checking for operating folder...' -ForegroundColor Yellow -NoNewline
$SandboxOperatingFolder = 'C:\SandboxEnvironment\bin'
[string] $module = (Get-Command -Name $MyInvocation.MyCommand -All).Source
$PathModule = (Get-Module -Name $module.Trim() | Select-Object ModuleBase -First 1).ModuleBase
If (!(Test-Path -Path $SandboxOperatingFolder -PathType Container)) {
Write-Host 'Folder found!' -ForegroundColor Green
Write-Host "Copying crucial files to $SandboxOperatingFolder" -ForegroundColor Yellow
Copy-Item -Path $PathModule\Configuration\* -Recurse -Destination $SandboxOperatingFolder -Force
Write-Host "Copying helpers files to C:\SandboxEnvironment" -ForegroundColor Yellow
Copy-Item -Path $PathModule\Helpers\* -Recurse -Destination 'C:\SandboxEnvironment' -Force
}
Write-Host 'All done!' -ForegroundColor Green
Pause
}
13 changes: 13 additions & 0 deletions build/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$Global:ErrorActionPreference = 'Stop'
$Global:VerbosePreference = 'SilentlyContinue'

### Prepare NuGet / PSGallery
if (!(Get-PackageProvider | Where-Object { $_.Name -eq 'NuGet' })) {
"Installing NuGet"
Install-PackageProvider -Name NuGet -force | Out-Null
}
"Preparing PSGallery repository"
Import-PackageProvider -Name NuGet -force | Out-Null
if ((Get-PSRepository -Name PSGallery).InstallationPolicy -ne 'Trusted') {
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
}
11 changes: 11 additions & 0 deletions tests/Unit.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Describe "CHECK CONFIGURATION FILES ARE PRESENT" {
It "Check configuration files are present" {
(Get-ChildItem .\Intune-App-Sandbox\Configuration\* -Recurse | Measure-Object).Count | Should -Be 8
}
$Files = ('intunewin-Box-icon.ico', 'IntuneWinAppUtil.exe', 'IntuneWinAppUtilDecoder.exe', 'Invoke-IntunewinUtil.ps1', 'Invoke-Test.ps1', 'New-ToastNotification.ps1', 'sandbox.ico', 'toast.xml')
foreach ($item in $Files) {
It "Checking for $item" {
Test-Path .\Intune-App-Sandbox\Configuration\$item | Should -Be $true
}
}
}

0 comments on commit b403eb1

Please sign in to comment.