Skip to content

Commit 2f8b0d5

Browse files
authored
Dev (#19)
* WIP. Added PSSA, renamed some functions, added some new ones as well. * WIP: Updated function names, added some better pipeline usability, and outputs custom object classes now * WIP: Added a new class, converted to some more pipeline stuff * Added multiple available pipeline types * WIP: Started adding custom query Has much more work to be done. * Changed to a select string array, instead of PSCustomObject, for the custom queries * Create Write-ePOWhere.ps1 * Update Write-ePOWhere.ps1 * Update Write-ePOWhere.ps1 * Sharing current so I can go home. * New class builder * CmdletBinding and updated variable names * Fixed example names * Fixed example function name * More logging * Added pipeline, simplified function, and returns an object now * Needs a hashtable * Removed file * Deleted file * Changed to use IWR, and handling to PS Core * Updated documentation * Renamed files, starting to work on pester tests * Sharing current * Added * Updated and added some pester test * Added some more pester tests * Updated pester tests, and cleaned up unnecessary ones too * Finished pester tests for Get-ePOQuery * Added testing for ePOTag, ePOVersion, and updated functions for better pipelining. * Re-added the manifest file * Lots of work... * Removed * Fixed parameters * Removed * Added /dev to ignore * Updated * Updated/Fixed tests and cleaned up code * Added function with tests * Forgot the export * Changed repo root * changed back to root * Cleaned up, and added skip_tags * Added -t * Updated README.md * Cleaned up * Removed branch * Removed codecov * Updated README.md to remove codecov * Changed dependency * Updated * Removed skip tag and cleaned up * Forgot error checking * ...meh * Fixed spacing * Re-added enable exit * Removed global * Fixed function name and cleaned up expletive * Changed to warning and added parent ID * Added a foreach * Fixed parameter name * added some logging
1 parent 7826fae commit 2f8b0d5

337 files changed

Lines changed: 4971 additions & 3457 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.appveyor.yml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ environment:
1212
secure: 19uAs7mfu9YRkwTvHIymJuSyXGjUUXCR+jsaRvo3ST44NmgZG2HZkOjuabTe/Cyu
1313
CODECOV_TOKEN:
1414
secure: 2zRKXm7Sw+GlVonpMOerfEBjeYc05cJinePPX8nJl7c7j1PzNAbrNHAbi7y1RALU
15+
1516

1617

1718

@@ -25,27 +26,12 @@ install:
2526
2627
2728
build_script:
28-
- ps: Invoke-psake '.\.scripts\build.ps1' -Properties @{'SkipBootStrap' = $true}
29-
30-
31-
32-
# deploy:
33-
# release: v$(APPVEYOR_BUILD_VERSION)
34-
# description: ePOwerShell v$(appveyor_build_version)
35-
# provider: GitHub
36-
# auth_token:
37-
# secure: EHLdOgH35OJQ/AAj6dXn/iQ9datyBKgai5JGB+Lbh9Yaltk4wLefi2MIfGZ5N2ca
38-
# artifact: /.*\.zip/
39-
# draft: false
40-
# prerelease: true
41-
# on:
42-
# branch: master # release from master branch only
43-
# appveyor_repo_tag: false # deploy except on tag push only
29+
- ps: Invoke-psake '.\.scripts\build.ps1'
4430

4531

4632

4733
on_success:
4834
# If build was started by pushed tag; deploy it.
49-
- ps: |
50-
Write-Host "[AppVeyor] On Success; deploying ..." -Foregroundcolor Green
51-
Invoke-PSDeploy -Path '.\.scripts\deploy.ps1' -Force
35+
- ps: |
36+
Write-Host "[AppVeyor] On Success; deploying ..." -Foregroundcolor Green
37+
Invoke-PSDeploy -Path '.\.scripts\deploy.ps1' -Force

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
settings.json
2+
/*.code-workspace
3+
./dev/*
4+
/dev

.scripts/build.ps1

Lines changed: 85 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
May do different tasks depending on the environment it's running in. Read the code for the details on that.
99
.Example
1010
# Run this Build Script:
11-
11+
1212
Invoke-psake .\.build.ps1
1313
.Example
1414
# Skip Bootstrap
@@ -20,14 +20,14 @@
2020
Invoke-psake .\.build.ps1 -Properties @{'thisModuleName'='OtherModuleName'}
2121
.Example
2222
# Run this Build Script with a parameters/properties that's not otherwise defined:
23-
23+
2424
Invoke-psake .\.build.ps1 -Properties @{'Version'=[version]'1.2.3'}
2525
#>
2626
$ErrorActionPreference = 'Stop'
2727

2828
$script:thisModuleName = 'ePOwerShell'
2929
$script:PSScriptRootParent = Split-Path $PSScriptRoot -Parent
30-
$script:ManifestJsonFile = "${PSScriptRootParent}\${thisModuleName}\Manifest.json"
30+
$script:ManifestJsonFile = "${PSScriptRootParent}\Manifest.json"
3131
$script:BuildOutput = "${PSScriptRootParent}\dev\BuildOutput"
3232

3333
$script:Manifest = @{}
@@ -62,8 +62,6 @@ Properties {
6262
$ManifestJsonFile = $script:ManifestJsonFile
6363
$BuildOutput = $script:BuildOutput
6464

65-
# Manipulate the Parameters for usage:
66-
6765
$script:Manifest.Copyright = $script:Manifest.Copyright -f [DateTime]::Now.Year
6866
$script:Manifest.GUID = (New-Guid).Guid
6967

@@ -78,149 +76,113 @@ Properties {
7876
$script:Version = [string](& "${PSScriptRootParent}\.scripts\version.ps1")
7977
}
8078

81-
# Start psake builds
79+
8280
Task default -Depends CompressModule
8381

84-
<#
85-
Bootstrap PSDepend:
86-
- https://github.com/RamblingCookieMonster/PSDepend
87-
Install Dependencies
88-
#>
89-
Task Bootstrap -Description "Bootstrap & Run PSDepend" {
90-
$PSDepend = Get-Module -Name 'PSDepend'
91-
Write-Host "[BUILD Bootstrap] PSDepend: $($PSDepend.Version)" -ForegroundColor Magenta
92-
if ($PSDepend)
93-
{
94-
Write-Host "[BUILD Bootstrap] PSDepend: Updating..." -ForegroundColor Magenta
95-
$PSDepend | Update-Module -Force
96-
}
97-
else
98-
{
99-
Write-Host "[BUILD Bootstrap] PSDepend: Installing..." -ForegroundColor Magenta
100-
Install-Module -Name 'PSDepend' -Force
82+
Task Clean -Description 'Cleans the build environment' {
83+
if (Test-Path $ParentModulePath) {
84+
Write-Host "[BUILD Clean] Parent module path exists: $ParentModulePath" -ForegroundColor Magenta
85+
86+
if ((Get-ChildItem $ParentModulePath | Measure-Object).Count -ne 0) {
87+
Write-Host "[BUILD Clean] Parent module path is not empty: $(Get-ChildItem $ParentModulePath)" -ForegroundColor Magenta
88+
Remove-Item "$ParentModulePath\*" -Recurse -Force
89+
}
90+
} else {
91+
Write-Host "[BUILD Clean] Parent module path does not exist: $ParentModulePath" -ForegroundColor Magenta
92+
93+
New-Item -ItemType Directory -Path $ParentModulePath -Force
10194
}
10295

103-
Write-Host "[BUILD Bootstrap] PSDepend: Installing..." -ForegroundColor Magenta
104-
$PSDepend = Import-Module -Name 'PSDepend' -PassThru
105-
Write-Host "[BUILD Bootstrap] PSDepend: $($PSDepend.Version)" -ForegroundColor Magenta
96+
if (Get-Module -Name $script:thisModuleName) {
97+
Write-Host "[BUILD Clean] Module is imported: $(Get-Module -Name $script:thisModuleName)" -ForegroundColor Magenta
10698

107-
Write-Host "[BUILD Bootstrap] PSDepend: Invoking '${PSScriptRootParent}\REQUIREMENTS.psd1'" -ForegroundColor Magenta
108-
Push-Location $PSScriptRootParent
109-
Invoke-PSDepend -Path "${PSScriptRootParent}\REQUIREMENTS.psd1" -Force
110-
Pop-Location
99+
Remove-Module -Name $script:thisModuleName -Force
100+
}
111101
}
112102

113-
<#
114-
Preperation and Setup:
115-
- Import Manifest.json to create the PDS1 file.
116-
- Modify Manifest information; keeping purged information.
117-
- Establish Module/Resource Locations/Paths.
118-
#>
119-
Task SetupModule -Description "Prepare and Setup Module" -Depends $DependsBootstrap {
120-
New-Item -ItemType Directory -Path $script:ParentModulePath -Force
121-
103+
Task CompileManifest -Description 'Created the module .psd1 manifest file' -Depends Clean {
122104
$script:Manifest.Path = "${script:ParentModulePath}\${script:Manifest_ModuleName}.psd1"
123-
$script:Manifest.ModuleVersion = $script:Version
124-
Write-Host "[BUILD SetupModule] New-ModuleManifest: $($script:Manifest | ConvertTo-Json -Compress)" -ForegroundColor Magenta
105+
if ($env:APPVEYOR_REPO_TAG -eq 'true') {
106+
try {
107+
[Version] $env:APPVEYOR_REPO_TAG_NAME
108+
$script:Manifest.ModuleVersion = $env:APPVEYOR_REPO_TAG_NAME
109+
} catch {
110+
$script:Manifest.ModuleVersion = $script:Version
111+
}
112+
} else {
113+
$script:Manifest.ModuleVersion = $script:Version
114+
}
115+
Write-Host "[BUILD CompileManifest] New-ModuleManifest: $($script:Manifest | ConvertTo-Json -Compress)" -ForegroundColor Magenta
125116
New-ModuleManifest @script:Manifest
117+
}
118+
119+
120+
Task PSScriptAnalyzer -Description 'Runs PSScriptAnalyzer against compiled module' -Depends Clean {
121+
$PSSAResults = Invoke-ScriptAnalyzer -Path "${PSScriptRootParent}\${thisModuleName}" -Settings "${script:PSScriptRootParent}\PSScriptAnalyzerSettings.psd1" -Recurse
126122

127-
$copyItem = @{
128-
LiteralPath = "${PSScriptRootParent}\${script:thisModuleName}\${script:thisModuleName}.psm1"
129-
Destination = $script:ParentModulePath
130-
Force = $true
123+
$Information = $PSSAResults | Where-Object { $_.Severity -eq 'Information' }
124+
$Errors = $PSSAResults | Where-Object { $_.Severity -eq 'Error' }
125+
$Warnings = $PSSAResults | Where-Object { $_.Severity -eq 'Warning' }
126+
$ParseErrors = $PSSAResults | Where-Object { $_.Severity -eq 'ParseError' }
127+
128+
if ($Information) {
129+
Write-Host "PSSA Information:"
130+
$Information
131131
}
132-
Write-Host "[BUILD SetupModule] Copy-Item: $($copyItem | ConvertTo-Json -Compress)" -ForegroundColor Magenta
133-
Copy-Item @copyItem
134-
135-
foreach ($directory in (Get-ChildItem "${PSScriptRootParent}\${thisModuleName}" -Directory)) {
136-
$copyItem = @{
137-
LiteralPath = $directory.FullName
138-
Destination = $script:ParentModulePath
139-
Recurse = $true
140-
Force = $true
141-
}
142-
Write-Host "[BUILD SetupModule] Copy-Item: $($copyItem | ConvertTo-Json -Compress)" -ForegroundColor Magenta
143-
Copy-Item @copyItem
132+
133+
if ($Warnings) {
134+
Write-Host "PSSA Warnings:"
135+
$Warnings
136+
}
137+
138+
if ($Errors) {
139+
Write-Error "PSSA Errors"
140+
Throw $Errors
141+
} elseif ($ParseErrors) {
142+
Write-Error "PSSA Parse Errors"
143+
Throw $ParseErrors
144144
}
145145
}
146146

147-
<#
148-
Put Module/Resource in locations accessible by DSC:
149-
- Create the PSD1 files from Manifest.
150-
- Copy PSM1 to location.
151-
- Copy Module to System Location; for testing.
152-
#>
153-
Task InstallModule -Description "Prepare and Setup/Install Module" -Depends SetupModule {
154-
$New_Item = @{
155-
ItemType = 'Directory'
156-
Path = $script:SystemModuleLocation
157-
Force = $true
147+
Task CompileModule -Description 'Compiles all funcitons into a single .psm1 file' -Depends PSScriptAnalyzer {
148+
$CompiledModule = "${script:ParentModulePath}\${script:Manifest_ModuleName}.psm1"
149+
$Files = Get-ChildItem -Path "${PSScriptRootParent}\${thisModuleName}" -Recurse -File
150+
$FileContents = foreach ($File in $Files) {
151+
Get-Content $File.FullName -Force
158152
}
159-
Write-Host "[BUILD InstallModule] New-Item: $($New_Item | ConvertTo-Json -Compress)" -ForegroundColor Magenta
160-
New-Item @New_Item | Out-Null
161-
162-
$Copy_Item = @{
163-
Path = "${script:BuildOutput}\*"
164-
Destination = $script:SystemModuleLocation
165-
Recurse = $true
166-
Force = $true
153+
154+
$FileContents | Out-File -FilePath $CompiledModule -Force
155+
Write-Host "[BUILD CompileModule] Module: $CompiledModule" -ForegroundColor Magenta
156+
}
157+
158+
Task ImportModule -Description 'Imports the compiled module' -Depends CompileModule, CompileManifest {
159+
try {
160+
Import-Module "${script:ParentModulePath}\${script:Manifest_ModuleName}.psm1" -Force
161+
} catch {
162+
Throw $_
167163
}
168-
Write-Host "[BUILD InstallModule] Copy-Item: $($Copy_Item | ConvertTo-Json -Compress)" -ForegroundColor Magenta
169-
Copy-Item @Copy_Item
170164
}
171165

172-
<#
173-
Tests
174-
- Pester
175-
- CodeCov
176-
#>
177-
Task TestModule -Description "Run Pester Tests and CoeCoverage" -Depends InstallModule {
178-
Write-Host "[BUILD TestModule] Import-Module ${env:Temp}\CodeCovIo.psm1" -ForegroundColor Magenta
179-
Import-Module ${env:Temp}\CodeCovIo.psm1
180-
181-
$invokePester = @{
182-
Path = "${PSScriptRootParent}\Tests"
183-
CodeCoverage = (Get-ChildItem "${PSScriptRootParent}\${thisModuleName}" -Recurse -Include '*.psm1', '*.ps1').FullName
184-
PassThru = $true
166+
Task InvokePester -Description 'Runs Pester tests against compiled module' -Depends ImportModule {
167+
$InvokePester = @{
168+
Path = "${PSScriptRootParent}\Tests\"
169+
CodeCoverage = "${script:ParentModulePath}\${script:Manifest_ModuleName}.psm1"
170+
PassThru = $True
185171
OutputFormat = 'NUnitXml'
186172
OutputFile = ([IO.FileInfo] '{0}\dev\CodeCoverage.xml' -f $PSScriptRootParent)
187-
EnableExit = $True
173+
EnableExit = $True
188174
}
189-
Write-Host "[BUILD TestModule] Invoke-Pester $($invokePester | ConvertTo-Json)" -ForegroundColor Magenta
190-
$res = Invoke-Pester @invokePester
191-
# Write-Host "[BUILD TestModule] Pester Result: $($res | ConvertTo-Json)" -ForegroundColor Magenta
192-
193-
$exportCodeCovIoJson = @{
194-
CodeCoverage = $res.CodeCoverage
195-
RepoRoot = $PSScriptRootParent
196-
Path = ([string] $invokePester.OutputFile).Replace('.xml', '.json')
197-
}
198-
Write-Host "[BUILD TestModule] Export-CodeCovIoJson: $($exportCodeCovIoJson | ConvertTo-Json)" -ForegroundColor Magenta
199-
Export-CodeCovIoJson @exportCodeCovIoJson
200-
201-
Write-Host "[BUILD TestModule] Uploading CodeCov.io Report ..." -ForegroundColor Magenta
202-
Push-Location $script:PSScriptRootParent
203-
& "${env:Temp}\Codecov\codecov.exe" -f $exportCodeCovIoJson.Path
204-
Pop-Location
205-
206-
Write-Host "[BUILD TestModule] Adding Results to Artifacts..." -ForegroundColor Magenta
207-
# (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/${env:APPVEYOR_JOB_ID}", (Resolve-Path $invokePester.OutputFile))
208-
Push-AppveyorArtifact (Resolve-Path $invokePester.OutputFile)
209-
Push-AppveyorArtifact (Resolve-Path $exportCodeCovIoJson.Path)
210-
211-
if ($res.FailedCount -gt 0) {
212-
Throw "$($res.FailedCount) tests failed."
213-
# $Host.SetShouldExit($res.FailedCount)
214-
Exit $res.FailedCount
175+
176+
$Pester = Invoke-Pester @InvokePester
177+
178+
if ($Pester.FailedCount -gt 0) {
179+
Throw "$($Pester.FailedCount) tests failed."
215180
}
216181
}
217182

218-
<#
219-
Compress things for releasing
220-
#>
221-
Task CompressModule -Description "Compress module for easy download from GitHub" -Depends TestModule {
183+
Task CompressModule -Description "Compress module for easy download from GitHub" -Depends InvokePester {
222184
Write-Host "[BUILD CompressModule] Import-Module ${env:Temp}\CodeCovIo.psm1" -ForegroundColor Magenta
223185
Compress-Archive -Path $script:ParentModulePath -DestinationPath "${script:ParentModulePath}.zip"
224186

225187
Push-AppveyorArtifact (Resolve-Path "${script:ParentModulePath}.zip")
226-
}
188+
}

.scripts/deploy.ps1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ Write-Host "[Deploy] APPVEYOR_PROJECT_NAME: ${env:APPVEYOR_PROJECT_NAME}" -Foreg
88
Write-Host "[Deploy] APPVEYOR_REPO_TAG: ${env:APPVEYOR_REPO_TAG}" -Foregroundcolor 'Blue' -BackgroundColor 'Magenta'
99
Write-Host "[Deploy] APPVEYOR_REPO_BRANCH: ${env:APPVEYOR_REPO_BRANCH}" -Foregroundcolor 'Blue' -BackgroundColor 'Magenta'
1010

11-
if (
12-
($env:APPVEYOR_REPO_TAG -eq 'true') -and
13-
($env:APPVEYOR_REPO_BRANCH -eq 'master')
14-
) {
11+
if (($env:APPVEYOR_REPO_TAG -eq 'true') -and ($env:APPVEYOR_REPO_BRANCH -eq 'master')) {
1512
Write-Host "Deploying to PSGallery"
1613
Deploy Module {
1714
By PSGalleryModule ePOwerShell {

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"editor.tabSize": 4,
3+
"powershell.codeFormatting.preset": "OTBS",
4+
"powershell.codeFormatting.openBraceOnSameLine":true,
5+
"powershell.codeFormatting.useCorrectCasing": true,
6+
"powershell.codeFormatting.whitespaceAroundPipe": true,
7+
"powershell.codeFormatting.whitespaceBeforeOpenParen": true,
8+
"powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1"
9+
}

Examples/Find-ePOwerShellComputerSystem/Find-ePOwerShellComputerSystem.Find_Five_Computers_By_Agent_Guid.psd1

Lines changed: 0 additions & 15 deletions
This file was deleted.

Examples/Find-ePOwerShellComputerSystem/Find-ePOwerShellComputerSystem.Find_Five_Computers_By_IP_Address.psd1

Lines changed: 0 additions & 15 deletions
This file was deleted.

Examples/Find-ePOwerShellComputerSystem/Find-ePOwerShellComputerSystem.Find_Five_Computers_By_Unique_Tags.psd1

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)