Skip to content

Commit 4b7ea28

Browse files
committed
Merge branch 'develop' into feature/eslint
2 parents f12959a + 398cf9f commit 4b7ea28

File tree

9 files changed

+304
-17
lines changed

9 files changed

+304
-17
lines changed

packages/launchpad/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @bluecadet/launchpad
22

3+
## 1.3.9
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [[`852ed2f`](https://github.com/bluecadet/launchpad/commit/852ed2f0e10f00210f91ec37e7d087f7cebe7911)]:
8+
- @bluecadet/launchpad-scaffold@1.6.0
9+
310
## 1.3.8
411

512
### Patch Changes

packages/launchpad/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bluecadet/launchpad",
3-
"version": "1.3.8",
3+
"version": "1.3.9",
44
"description": "Suite of tools to manage media installations",
55
"engines": {
66
"npm": ">=8.5.1",
@@ -46,7 +46,7 @@
4646
"@bluecadet/launchpad-utils": "~1.3.2",
4747
"@bluecadet/launchpad-dashboard": "~1.3.0",
4848
"@bluecadet/launchpad-monitor": "~1.6.0",
49-
"@bluecadet/launchpad-scaffold": "~1.5.0",
49+
"@bluecadet/launchpad-scaffold": "~1.6.0",
5050
"@bluecadet/launchpad-content": "~1.9.0",
5151
"chalk": "^5.0.0",
5252
"fs-extra": "^10.0.0"

packages/scaffold/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @bluecadet/launchpad-scaffold
22

3+
## 1.6.0
4+
5+
### Minor Changes
6+
7+
- [#96](https://github.com/bluecadet/launchpad/pull/96) [`852ed2f`](https://github.com/bluecadet/launchpad/commit/852ed2f0e10f00210f91ec37e7d087f7cebe7911) Thanks [@benjaminbojko](https://github.com/benjaminbojko)! - Fixes powerplan selection and powershell7 compatibility
8+
39
## 1.5.0
410

511
### Minor Changes

packages/scaffold/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bluecadet/launchpad-scaffold",
3-
"version": "1.5.0",
3+
"version": "1.6.0",
44
"description": "Suite of PS1 scripts to configure Windows 8/10 PCs for permanent exhibits.",
55
"type": "module",
66
"main": "index.js",

packages/scaffold/scripts/functions.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ function Disable-Service(
123123
[String]$ComputerName = "$(hostname)"
124124
) {
125125
# See https://social.technet.microsoft.com/Forums/lync/en-US/abde2699-0d5a-49ad-bfda-e87d903dd865/disable-windows-update-via-powershell?forum=winserverpowershell
126-
$service = Get-WmiObject Win32_Service -Filter "Name='$ServiceName'" -ComputerName $ComputerName -Ea 0;
126+
$service = Get-CimInstance win32_service -Filter "Name='$ServiceName'" -Ea 0;
127127
if ($service) {
128128
if ($service.StartMode -ne "Disabled") {
129-
$result = $service.ChangeStartMode("Disabled").ReturnValue;
129+
$result = (Invoke-CimMethod -InputObject $service -methodname ChangeStartmode -Arguments @{startmode='Disabled'}).ReturnValue;
130130
if ($result) {
131131
Write-Host "Failed to disable the '$ServiceName' service on $ComputerName. The return value was $result." -ForegroundColor Red;
132132
} else {
133133
Write-Host "Successfully disabled the '$ServiceName' service on $ComputerName." -ForegroundColor Green;
134134
}
135135
if ($service.State -eq "Running") {
136-
$result = $service.StopService().ReturnValue;
136+
$result = (Invoke-CimMethod -InputObject $service -methodname StopService).ReturnValue.ReturnValue;
137137
if ($result) {
138138
Write-Host "Failed to stop the '$ServiceName' service on $ComputerName. The return value was $result." -ForegroundColor Red;
139139
} else {
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
# See https://github.com/torgro/PowerPlan
2+
3+
function Get-Powerplan
4+
{
5+
<#
6+
.Synopsis
7+
Get a Powerplan by name or all of them
8+
.DESCRIPTION
9+
This cmdlet queries the CIM class Win32_PowerPlan. See also Set-PowerPlan cmdlet
10+
.EXAMPLE
11+
Get-Powerplan
12+
This command will output all powerplans:
13+
Caption :
14+
Description : Automatically balances performance with energy consumption on capable hardware.
15+
ElementName : Balanced
16+
InstanceID : Microsoft:PowerPlan\{381b4222-f694-41f0-9685-ff5bb260df2e}
17+
IsActive : False
18+
PSComputerName :
19+
Caption :
20+
Description : Favors performance, but may use more energy.
21+
ElementName : High performance
22+
InstanceID : Microsoft:PowerPlan\{8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c}
23+
IsActive : True
24+
PSComputerName :
25+
Caption :
26+
Description : Saves energy by reducing your computer’s performance where possible.
27+
ElementName : Power saver
28+
InstanceID : Microsoft:PowerPlan\{a1841308-3541-4fab-bc81-f71556f20b4a}
29+
IsActive : False
30+
PSComputerName :
31+
.EXAMPLE
32+
Get-Powerplan -PlanName high*
33+
This command will output all plans that begins with high
34+
Caption :
35+
Description : Favors performance, but may use more energy.
36+
ElementName : High performance
37+
InstanceID : Microsoft:PowerPlan\{8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c}
38+
IsActive : True
39+
PSComputerName :
40+
.EXAMPLE
41+
Get-PowerPlan -PlanName high* -ComputerName "Server1","Server2"
42+
Will output the powerplan with name like high for server1 and server2
43+
44+
.EXAMPLE
45+
Get-PowerPlan -Active
46+
Will output the active powerplan
47+
.OUTPUTS
48+
CimInstance
49+
.NOTES
50+
Powerplan and performance
51+
.COMPONENT
52+
Powerplan
53+
.ROLE
54+
Powerplan
55+
.FUNCTIONALITY
56+
This cmdlet queries the CIM class Win32_PowerPlan
57+
#>
58+
[cmdletbinding()]
59+
[OutputType([CimInstance[]])]
60+
Param(
61+
[Parameter(
62+
ValueFromPipeline=$true,
63+
ValueFromPipelineByPropertyName=$true,
64+
ValueFromRemainingArguments=$false
65+
)]
66+
[Alias("ElementName")]
67+
[string]$PlanName = "*"
68+
,
69+
[Parameter(
70+
ValueFromPipeline=$true,
71+
ValueFromPipelineByPropertyName=$true,
72+
ValueFromRemainingArguments=$false
73+
)]
74+
[string[]]$ComputerName,
75+
[switch]$Active
76+
)
77+
78+
Begin
79+
{
80+
$f = $MyInvocation.InvocationName
81+
Write-Verbose -Message "$f - START"
82+
83+
$GetCimInstance = @{
84+
Namespace = "root\cimv2\power"
85+
ClassName = "Win32_PowerPlan"
86+
}
87+
88+
if ($ComputerName)
89+
{
90+
$GetCimInstance.Add("ComputerName",$ComputerName)
91+
}
92+
93+
if ($Active)
94+
{
95+
$GetCimInstance.Add("Filter",'IsActive="True"')
96+
}
97+
}
98+
99+
Process
100+
{
101+
if ($PlanName)
102+
{
103+
Get-CimInstance @GetCimInstance | Where-Object ElementName -Like "$PlanName"
104+
}
105+
else
106+
{
107+
Get-CimInstance @GetCimInstance
108+
}
109+
}
110+
111+
End
112+
{
113+
Write-Verbose -Message "$f - END"
114+
}
115+
}
116+
117+
function Set-PowerPlan
118+
{
119+
<#
120+
.Synopsis
121+
Sets a Powerplan by name or by value provided from the pipeline
122+
.DESCRIPTION
123+
This cmdlet invokes the CIM-method Activate in class Win32_PowerPlan. See also Get-PowerPlan cmdlet
124+
.EXAMPLE
125+
Set-PowerPlan -PlanName high*
126+
This will set the current powerplan to High for the current computer
127+
.EXAMPLE
128+
Get-Powerplan -PlanName "Power Saver" | Set-PowerPlan
129+
Will set the powerplan to "Power Saver" for current computer
130+
.EXAMPLE
131+
Get-Powerplan -PlanName "Power Saver" -ComputerName "Server1","Server2" | Set-PowerPlan
132+
This will set the current powerpla to "Power Saver" for the computers Server1 and Server2
133+
.EXAMPLE
134+
Set-PowerPlan -PlanName "Power Saver" -ComputerName "Server1","Server2"
135+
This will set the current powerpla to "Power Saver" for the computers Server1 and Server2
136+
.NOTES
137+
Powerplan and performance
138+
.COMPONENT
139+
Powerplan
140+
.ROLE
141+
Powerplan
142+
.FUNCTIONALITY
143+
This cmdlet invokes CIM-methods in the class Win32_PowerPlan
144+
#>
145+
[cmdletbinding(
146+
SupportsShouldProcess=$true,
147+
ConfirmImpact='Medium'
148+
)]
149+
Param(
150+
[Parameter(
151+
ValueFromPipeline=$true,
152+
ValueFromPipelineByPropertyName=$true,
153+
ValueFromRemainingArguments=$false
154+
)]
155+
[Alias("ElementName")]
156+
[string]$PlanName = "*"
157+
,
158+
[Parameter(
159+
ValueFromPipeline=$true,
160+
ValueFromPipelineByPropertyName=$true,
161+
ValueFromRemainingArguments=$false
162+
)]
163+
[Alias("PSComputerName")]
164+
[string[]]$ComputerName
165+
)
166+
167+
Begin
168+
{
169+
$f = $MyInvocation.InvocationName
170+
Write-Verbose -Message "$f - START"
171+
$GetCimInstance = @{
172+
Namespace = "root\cimv2\power"
173+
ClassName = "Win32_PowerPlan"
174+
}
175+
176+
if ($ComputerName)
177+
{
178+
$GetCimInstance.Add("ComputerName",$ComputerName)
179+
}
180+
181+
$InvokeCimMethod = @{
182+
MethodName = "Activate"
183+
}
184+
185+
if ($WhatIfPreference)
186+
{
187+
$InvokeCimMethod.Add("WhatIf",$true)
188+
}
189+
}
190+
191+
Process
192+
{
193+
Write-Verbose -Message "$f - ElementName=$PlanName"
194+
$CimObjectPowerPlan = Get-CimInstance @GetCimInstance | Where-Object ElementName -like "$PlanName"
195+
196+
foreach ($Instance in $CimObjectPowerPlan)
197+
{
198+
if ($pscmdlet.ShouldProcess($Instance))
199+
{
200+
$null = Invoke-CimMethod -InputObject $Instance @InvokeCimMethod
201+
}
202+
}
203+
if (-not $CimObjectPowerPlan)
204+
{
205+
Write-Warning -Message "Unable to find powerplan $PlanName"
206+
}
207+
}
208+
209+
End
210+
{
211+
Write-Verbose -Message "$f - END"
212+
}
213+
214+
}
215+
216+
<#
217+
DSC Resource
218+
Manages the power plan selection for a computer.
219+
#>
220+
[DscResource()]
221+
class PowerPlan
222+
{
223+
224+
<#
225+
This property is the name of an available power plan.
226+
#>
227+
[DscProperty(Key)]
228+
[string]$Name
229+
230+
<#
231+
Sets the specified power plan as active.
232+
#>
233+
[void] Set()
234+
{
235+
Set-PowerPlan $this.Name
236+
}
237+
238+
<#
239+
Tests if the machine is using the specified power plan.
240+
#>
241+
[bool] Test()
242+
{
243+
if ((Get-PowerPlan -Active).ElementName -eq $this.Name)
244+
{
245+
return $true
246+
}
247+
else
248+
{
249+
return $false
250+
}
251+
}
252+
253+
<#
254+
Returns an instance of this class to identify the active plan.
255+
#>
256+
[PowerPlan] Get()
257+
{
258+
$this.Name = (Get-PowerPlan -Active).ElementName
259+
return $this
260+
}
261+
}

packages/scaffold/scripts/windows/disable_update_service.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@ try {
66
}
77

88
Write-Output "Disabling Windows Update Medic Service"
9+
# Windows Update Medic Service can only be disabled via the registry
910
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc' -Name 'Start' -value 4
10-
Disable-Service("WaaSMedicSVC");
11+
Write-Host "Successfully disabled the 'WaaSMedicSVC' service on $ComputerName." -ForegroundColor Green;
12+
$WaaSMedicSVC = get-ciminstance win32_service -Filter "Name='WaaSMedicSVC'" -Ea 0;
13+
if($WaaSMedicSVC.State -eq "Running"){
14+
$ComputerName = "$(hostname)"
15+
$result = (Invoke-CimMethod -InputObject $WaaSMedicSVC -methodname StopService).ReturnValue
16+
if ($result) {
17+
Write-Host "Failed to stop the 'WaaSMedicSVC' service on $ComputerName. The return value was $result." -ForegroundColor Red;
18+
} else {
19+
Write-Host "Successfully stopped the 'WaaSMedicSVC' service on $ComputerName." -ForegroundColor Green;
20+
}
21+
}
1122

1223
Write-Output "Disabling Update Orchestrator Service"
1324
Disable-Service("UsoSvc");

packages/scaffold/scripts/windows/enable_script_execution.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ force-mkdir "HKLM:\SOFTWARE\Policies\Microsoft\Windows"
66

77
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows" -Name "EnableScripts" -Type DWord -Value 1
88
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" -Name "ExecutionPolicy" -Type String -Value "RemoteSigned"
9-
10-
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
# Power Settings
22

33
param (
4-
[string]$configPath = $null
4+
[string]$planPath = $null
55
)
6-
if (($configPath -eq $null) -OR ($configPath -eq "") -OR !(Test-Path $configPath)) {
7-
$configPath = $Global:LaunchpadConfig.Computer.PowerConfig
6+
if (($planPath -eq $null) -OR ($planPath -eq "") -OR !(Test-Path $planPath)) {
7+
$planPath = $Global:LaunchpadConfig.Computer.PowerConfig
88
}
99

10-
Write-Host "Importing power config from $configPath"
10+
Import-Module -DisableNameChecking $PSScriptRoot/../vendor/powerplan.psm1
1111

12-
powercfg /IMPORT "$configPath"
12+
$planName = 'Exhibit'
1313

14-
# See https://stackoverflow.com/a/62222256/782899
15-
$p = Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan -Filter "ElementName = 'Exhibit'"
16-
powercfg /setactive ([string]$p.InstanceID).Replace("Microsoft:PowerPlan\{","").Replace("}","")
14+
Write-Host "Importing power plan '$planName' from $planPath"
15+
powercfg /IMPORT "$planPath"
16+
17+
Write-Host "Selecting power plan '$planName'"
18+
19+
# Using https://github.com/torgro/PowerPlan
20+
Set-Powerplan -Planname "$planName"

0 commit comments

Comments
 (0)