Skip to content

Commit

Permalink
10-add-get-fogversion (#14)
Browse files Browse the repository at this point in the history
Created Get-FogVersion and implmented check for 1.6 version
	so correct dynamic parameters are used for 1.5.x vs 1.6
	Also added a separate build test script for running a build test
	on each push.

* Add get-fogversion #10 - Updated dynamic params to be contextual to the version

* doc updates

* Cleaned up a couple things

* Added separate build script for use with testing builds on each push

* Increment version, update release notes

* trailing slash for import test

* try psscript root

* try importing with manifest

* fix build test script path syntax

* fix test for if module imported

* don't error when testing import, wait for check for loaded module

* Add built test badge to show if current master branch is passing build test
  • Loading branch information
darksidemilk authored Aug 18, 2024
1 parent 0d249b2 commit 585b3b0
Show file tree
Hide file tree
Showing 60 changed files with 2,529 additions and 267 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test Build

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Run build script
run: |
# Install-PSResource -Name PlatyPS -TrustRepository -Version 0.14.2 -Scope CurrentUser -AcceptLicense
$moduleName="FogApi";
.\invoke-modulebuild.ps1
$builtPath = ".\_module_build\$moduleName"
ls -recurse $builtPath;
if (Test-Modulemanifest -path "$builtPath\$moduleName.psd1") {
import-module "$builtPath\" -ea 0
if ($null -ne (Get-module $modulename -ea 0)) {
"Built module imported successfully!`n$((Get-module $modulename) | out-string)" | out-host
return $true;
} else {
Write-Error "Failed to import module!"
return $false;
}
} else {
Write-Error "Manifest threw error"
return $false;
}
34 changes: 0 additions & 34 deletions .github/workflows/build-test.yml.notready

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
_build
_module_build
.lastprereqrun
20 changes: 12 additions & 8 deletions FogApi/FogApi.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: JJ Fullmer
#
# Generated on: 11/17/2023
# Generated on: 8/18/2024
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'FogApi.psm1'

# Version number of this module.
ModuleVersion = '2311.6.4'
ModuleVersion = '2408.6.9'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -130,10 +130,11 @@ FunctionsToExport = 'Add-FogHostMac', 'Add-FogResultData', 'Approve-FogPendingMa
'Get-FogMacAddresses', 'Get-FogModules', 'Get-FogObject',
'Get-FogSecsSinceEpoch', 'Get-FogServerSettings',
'Get-FogServerSettingsFile', 'Get-FogSnapinAssociations',
'Get-FogSnapins', 'Get-LastImageTime', 'Install-FogService',
'Invoke-FogApi', 'New-FogHost', 'New-FogObject', 'Receive-FogImage',
'Remove-FogObject', 'Remove-UsbMac', 'Repair-FogSnapinAssociations',
'Reset-HostEncryption', 'Resolve-HostID', 'Send-FogImage',
'Get-FogSnapins', 'Get-FogVersion', 'Get-LastImageTime',
'Install-FogService', 'Invoke-FogApi', 'New-FogHost', 'New-FogObject',
'Receive-FogImage', 'Remove-FogObject', 'Remove-UsbMac',
'Repair-FogSnapinAssociations', 'Reset-HostEncryption',
'Resolve-HostID', 'Send-FogImage', 'Send-FogWolTask',
'Set-FogInventory', 'Set-FogServerSettings',
'Set-FogServerSettingsFileSecurity', 'Set-FogSnapins',
'Start-FogSnapin', 'Start-FogSnapins', 'Update-FogObject'
Expand Down Expand Up @@ -182,9 +183,12 @@ PrivateData = @{

# ReleaseNotes of this module
ReleaseNotes = '
# 2311.6.4
# 2408.6.9
typo bug fix there was a stray extra character. Also added switch for Set-FogSnapins called -repairBeforeAdd to allow running the repair before attempting to add. Also added in more try catch logic to set-fogsnapins. Also cleaned up release notes in manifest to just include the latest release to allow for faster import of module'
Created Get-FogVersion and implmented check for 1.6 version
so correct dynamic parameters are used for 1.5.x vs 1.6
Also added a separate build test script for running a build test
on each push.'

# Prerelease string of this module
# Prerelease = ''
Expand Down
36 changes: 25 additions & 11 deletions FogApi/Private/Get-DynmicParam.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,31 @@ the position to put the dynamic parameter in

$attributeCollection.Add($attributes)

$coreObjects = @(
"clientupdater", "dircleaner", "greenfog", "group", "groupassociation",
"history", "hookevent", "host", "hostautologout", "hostscreensetting", "image",
"imageassociation", "imagepartitiontype", "imagetype", "imaginglog", "inventory", "ipxe",
"keysequence", "macaddressassociation", "module", "moduleassociation", "multicastsession",
"multicastsessionassociation", "nodefailure", "notifyevent", "os", "oui", "plugin",
"powermanagement", "printer", "printerassociation", "pxemenuoptions", "scheduledtask",
"service", "setting", "snapin", "snapinassociation", "snapingroupassociation", "snapinjob",
"snapintask", "storagegroup", "storagenode", "task", "tasklog", "taskstate", "tasktype",
"unisearch", "user", "usercleanup", "usertracking", "virus"
);
if ((Get-FogVersion) -like '1.6*') {
$coreObjects = @(
"group", "groupassociation", "history", "hookevent", "host", "hostautologout",
"hostscreensetting", "image", "imageassociation", "imagepartitiontype", "imagetype",
"imaginglog", "inventory", "ipxe", "keysequence", "macaddressassociation", "module",
"moduleassociation", "multicastsession", "multicastsessionassociation", "nodefailure",
"notifyevent", "os", "oui", "plugin", "powermanagement", "printer", "printerassociation",
"pxemenuoptions", "scheduledtask", "setting", "snapin", "snapinassociation",
"snapingroupassociation", "snapinjob", "snapintask", "storagegroup", "storagenode", "task",
"tasklog", "taskstate", "tasktype", "unisearch", "user", "usertracking", "setting", "user"
);
} else {
$coreObjects = @(
"clientupdater", "dircleaner", "greenfog", "group", "groupassociation",
"history", "hookevent", "host", "hostautologout", "hostscreensetting", "image",
"imageassociation", "imagepartitiontype", "imagetype", "imaginglog", "inventory", "ipxe",
"keysequence", "macaddressassociation", "module", "moduleassociation", "multicastsession",
"multicastsessionassociation", "nodefailure", "notifyevent", "os", "oui", "plugin",
"powermanagement", "printer", "printerassociation", "pxemenuoptions", "scheduledtask",
"service", "setting", "snapin", "snapinassociation", "snapingroupassociation", "snapinjob",
"snapintask", "storagegroup", "storagenode", "task", "tasklog", "taskstate", "tasktype",
"unisearch", "user", "usercleanup", "usertracking", "virus"
);
}

$coreTaskObjects = @("group", "host", "multicastsession", "scheduledtask", "snapinjob", "snapintask", "task");
$coreActiveTaskObjects = @("multicastsession", "powermanagement", "scheduledtask", "snapinjob", "snapintask", "task");
}
Expand Down
8 changes: 1 addition & 7 deletions FogApi/Public/Find-FogObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function Find-FogObject {

DynamicParam { $paramDict = Set-DynamicParams $type; return $paramDict;}

begin {
process {
$paramDict | ForEach-Object { New-Variable -Name $_.Keys -Value $($_.Values.Value);}
# $paramDict;
Write-Verbose "Building uri and api call for $($paramDict.keys) $($paramDict.values.value)";
Expand All @@ -67,13 +67,7 @@ function Find-FogObject {
uriPath=$uri;
Method="GET";
}
}

process {
$result = Invoke-FogApi @apiInvoke;
}

end {
#convert the output to use the data property added in fog 1.6
if ($coreObject -ne "unisearch") {
$result = Add-FogResultData $result;
Expand Down
78 changes: 39 additions & 39 deletions FogApi/Public/Get-FogInventory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,46 @@ function Get-FogInventory {
$baseBoard = Get-CimInstance -ClassName Win32_BaseBoard;
$case = Get-CimInstance -ClassName Win32_SystemEnclosure;
$info = Get-ComputerInfo;
$hostObj.inventory.hostID = $hostObj.id;
# $hostObj.inventory.primaryUser =
# $hostObj.inventory.other1 =
# $hostObj.inventory.other2 =
$hostObj.inventory.createdTime = $((get-date -format u).replace('Z',''));
# $hostObj.inventory.deleteDate = '0000-00-00 00:00:00'
$hostObj.inventory.sysman = $compSys.Vendor; #manufacturer
$hostObj.inventory.sysproduct = $compSys.Name; #model
$hostObj.inventory.sysversion = $compSys.Version;
$hostObj.inventory.sysserial = $compSys.IdentifyingNumber;
if ($compSys.UUID -notmatch "12345678-9012-3456-7890-abcdefabcdef" ) {
$hostObj.inventory.sysuuid = $compSys.UUID;
} else {
$hostObj.inventory.sysuuid = ($compSys.Qualifiers | Where-Object Name -match 'UUID' | Select-Object -ExpandProperty Value);
}
$hostObj.inventory.systype = $case.chassistype; #device form factor found chassistype member of $case but it references a list that hasn't been updated anywhere I can find. i.e. returns 35 for a minipc but documented list only goes to 24
$hostObj.inventory.biosversion = $bios.name;
$hostObj.inventory.biosvendor = $bios.Manufacturer;
$hostObj.inventory.biosdate = $(get-date $info.BiosReleaseDate -Format d);
$hostObj.inventory.mbman = $baseBoard.Manufacturer;
$hostObj.inventory.mbproductname = $baseBoard.Product;
$hostObj.inventory.mbversion = $baseBoard.Version;
$hostObj.inventory.mbserial = $baseBoard.SerialNumber;
$hostObj.inventory.mbasset = $baseBoard.Tag;
$hostObj.inventory.cpuman = $cpu.Manufacturer;
$hostObj.inventory.cpuversion = $cpu.Name;
$hostObj.inventory.cpucurrent = "Current Speed: $($cpu.currentClockSpeed) MHz";
$hostObj.inventory.cpumax = "Max Speed $($cpu.MaxClockSpeed) MHz";
$hostObj.inventory.mem = "MemTotal: $($comp.TotalPhysicalMemory) kB";
$hostObj.inventory.hdmodel = $hdd.Model;
$hostObj.inventory.hdserial = $hdd.SerialNumber;
$hostObj.inventory.hdfirmware = $hdd.FirmareRevision;
$hostObj.inventory.caseman = $case.Manufacturer;
$hostObj.inventory.casever = $case.Version;
$hostObj.inventory.caseserial = $case.SerialNumber;
$hostObj.inventory.caseasset = $case.SMBIOSAssetTag;
$hostObj.inventory.memory = "$([MATH]::Round($(($comp.TotalPhysicalMemory) / 1GB),2)) GiB";
$jsonData = $hostObj.inventory | ConvertTo-Json;
return $jsonData;
}
$hostObj.inventory.hostID = $hostObj.id;
# $hostObj.inventory.primaryUser =
# $hostObj.inventory.other1 =
# $hostObj.inventory.other2 =
$hostObj.inventory.createdTime = $((get-date -format u).replace('Z',''));
# $hostObj.inventory.deleteDate = '0000-00-00 00:00:00'
$hostObj.inventory.sysman = $compSys.Vendor; #manufacturer
$hostObj.inventory.sysproduct = $compSys.Name; #model
$hostObj.inventory.sysversion = $compSys.Version;
$hostObj.inventory.sysserial = $compSys.IdentifyingNumber;
if ($compSys.UUID -notmatch "12345678-9012-3456-7890-abcdefabcdef" ) {
$hostObj.inventory.sysuuid = $compSys.UUID;
} else {
$hostObj.inventory.sysuuid = ($compSys.Qualifiers | Where-Object Name -match 'UUID' | Select-Object -ExpandProperty Value);
}
$hostObj.inventory.systype = $case.chassistype; #device form factor found chassistype member of $case but it references a list that hasn't been updated anywhere I can find. i.e. returns 35 for a minipc but documented list only goes to 24
$hostObj.inventory.biosversion = $bios.name;
$hostObj.inventory.biosvendor = $bios.Manufacturer;
$hostObj.inventory.biosdate = $(get-date $info.BiosReleaseDate -Format d);
$hostObj.inventory.mbman = $baseBoard.Manufacturer;
$hostObj.inventory.mbproductname = $baseBoard.Product;
$hostObj.inventory.mbversion = $baseBoard.Version;
$hostObj.inventory.mbserial = $baseBoard.SerialNumber;
$hostObj.inventory.mbasset = $baseBoard.Tag;
$hostObj.inventory.cpuman = $cpu.Manufacturer;
$hostObj.inventory.cpuversion = $cpu.Name;
$hostObj.inventory.cpucurrent = "Current Speed: $($cpu.currentClockSpeed) MHz";
$hostObj.inventory.cpumax = "Max Speed $($cpu.MaxClockSpeed) MHz";
$hostObj.inventory.mem = "MemTotal: $($comp.TotalPhysicalMemory) kB";
$hostObj.inventory.hdmodel = $hdd.Model;
$hostObj.inventory.hdserial = $hdd.SerialNumber;
$hostObj.inventory.hdfirmware = $hdd.FirmareRevision;
$hostObj.inventory.caseman = $case.Manufacturer;
$hostObj.inventory.casever = $case.Version;
$hostObj.inventory.caseserial = $case.SerialNumber;
$hostObj.inventory.caseasset = $case.SMBIOSAssetTag;
$hostObj.inventory.memory = "$([MATH]::Round($(($comp.TotalPhysicalMemory) / 1GB),2)) GiB";
$jsonData = $hostObj.inventory | ConvertTo-Json;
return $jsonData;
}


Expand Down
8 changes: 1 addition & 7 deletions FogApi/Public/Set-FogInventory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@ the jsondata with the inventory
$jsonData = (Get-FogInventory -hostObj $hostObj)
)

begin {
process {
$inventoryApi = @{
jsonData = $jsonData;
Method = 'Post';
uriPath = "inventory/new";
}
}

process {
Invoke-FogApi @inventoryApi -verbose;
}

end {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Overview

[![Test Build](https://github.com/darksidemilk/FogApi/actions/workflows/build-test.yml/badge.svg)](https://github.com/darksidemilk/FogApi/actions/workflows/build-test.yml)

This is a powershell module to make using the Fog Project API even easier.
FOG is an opensource tool for imaging comptuters, this module uses the API on your internal fog server to perform almost any operation. It can be used to create more automation or to simply have a command line method of controlling fog operations.

Expand Down
4 changes: 3 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,6 @@ $newContent += "`n`n"
$newContent += "### $newVer`n`n`t$releaseNote`n"
$newContent += $curNotes
# pause;
Set-Content -Path "$docsPth\ReleaseNotes.md" -value $newContent
Set-Content -Path "$docsPth\ReleaseNotes.md" -value $newContent

return $buildPth;
12 changes: 12 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## 6.x

### 2408.6.9

Created Get-FogVersion and implmented check for 1.6 version
so correct dynamic parameters are used for 1.5.x vs 1.6
Also added a separate build test script for running a build test
on each push.

### 2311.6.4

typo bug fix there was a stray extra character. Also added switch for Set-FogSnapins called -repairBeforeAdd to allow running the repair before attempting to add. Also added in more try catch logic to set-fogsnapins. Also cleaned up release notes in manifest to just include the latest release to allow for faster import of module
Expand Down Expand Up @@ -298,3 +305,8 @@
* Added hostID param to get-foghost so you can get a host from the internal hostID if you already have that







17 changes: 16 additions & 1 deletion docs/commands/Add-FogHostMac.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Adds a given macaddress to a host of a given ID

```
Add-FogHostMac [[-hostID] <Object>] [[-macAddress] <Object>] [-primary] [-ignoreMacOnClient]
[-ignoreMacForImaging] [-forceUpdate] [<CommonParameters>]
[-ignoreMacForImaging] [-forceUpdate] [-ProgressAction <ActionPreference>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -129,6 +129,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
Expand Down
Loading

0 comments on commit 585b3b0

Please sign in to comment.