Skip to content

Commit d90e43e

Browse files
authored
Merge pull request #17 from MWGMorningwood/dev
Dev
2 parents fdcec22 + 6fad4ba commit d90e43e

11 files changed

Lines changed: 100 additions & 53 deletions

Examples/Task Combined Script.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
param(
22
[Parameter(Position=0,Mandatory=$True,HelpMessage=@'
3-
Example task parameter. If you check off "use script params", this will be used in Immy.
3+
Example task parameter. If you check off "use script params", this will be used in Immy.
44
HelpMessage formatting supports MarkDown.
55
'@)]
66
[String]$list="stuff1,stuff2" #<- setting the variable here serves as a default for the parameter.
@@ -48,4 +48,4 @@ switch ($method) { # $method contains the current phase immy is in, values are g
4848
# Immy sessions will always have a $method, so this should primarily be informational.
4949
##################################################################################
5050
}
51-
}
51+
}

Function/Convert-AzureAdSidToObjectId.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<#
22
.SYNOPSIS
33
Convert a Azure AD SID to Object ID
4-
4+
55
.DESCRIPTION
66
Converts an Azure AD SID to Object ID.
77
Author: Oliver Kieselbach (oliverkieselbach.com)
88
The script is provided "AS IS" with no warranties.
9-
9+
1010
.PARAMETER ObjectID
1111
The SID to convert
1212
#>

Function/Enable-DellSMBIOS.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ Invoke-ImmyCommand {
3232
Write-Warning "PSDrive not found."
3333
Throw "Dell BIOS Provider preconfig failed."
3434
}
35-
}
35+
}

Function/Set-DellBIOSProvider.ps1

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#$BIOSPath = "PowerManagement\AutoOn"
2-
#$BIOSValue = "Everyday"
3-
#$method = "test"
41
param (
52
[Parameter(Mandatory=$true)]
63
[string]$Path,
@@ -9,42 +6,41 @@ param (
96
[string]$Value
107
)
118

12-
Ensure-PSModulePresent DellBiosProvider
9+
Write-Host "Ensuring DellBiosProvider is present"
10+
Ensure-PSModulePresent -RequiredModules DellBiosProvider -EnsureLatest $false
1311

1412
$BIOSPath = $Path
1513
$BIOSValue = $Value
1614

1715
switch ($method) {
1816
"test" {
19-
Invoke-ImmyCommand {
17+
$BIOSValue_Test = Invoke-ImmyCommand {
2018
Import-Module DellBIOSProvider
2119
try{
22-
$BIOSValue_Test = (Get-ChildItem -Path "DellSmbios:\$($using:BIOSPath)" -ErrorAction Stop).CurrentValue
20+
$Result = (Get-ChildItem -Path "DellSmbios:\$($using:BIOSPath)" -ErrorAction Stop).CurrentValue
21+
return $Result
2322
} catch {
24-
Write-Warning "Path failed to resolve. Please check script logs if this is unexpected."
25-
Write-Verbose $BIOSValue_Test
26-
return $false
23+
Write-Error "Path failed to resolve. $($_.Exception.Message)"
2724
}
25+
}
2826

29-
#Check actual setting value
30-
if ($BIOSValue_Test -eq $using:BIOSValue){
31-
Write-Host "Test results indicate success: $BIOSValue_Test"
32-
return $true
33-
} else {
34-
Write-Warning "Test results do not indicate success: $BIOSValue_Test"
35-
return $false
36-
}
27+
#Check actual setting value
28+
if ($BIOSValue_Test -eq $BIOSValue){
29+
Write-Host "Test results indicate success: $BIOSPath = $BIOSValue_Test"
30+
return $true
31+
} else {
32+
Write-Warning "Test results do not indicate success: $BIOSPath = $BIOSValue_Test"
33+
return $false
3734
}
3835
}
3936
"set" {
40-
#Enable-DellSMBIOS
37+
Write-Host "Setting BIOS Value in DellSmbios:\$BIOSPath to $BIOSValue..."
4138
Invoke-ImmyCommand {
4239
Import-Module DellBIOSProvider
43-
Write-Host "Setting BIOS Value in DellSmbios:\$($using:BIOSPath)..."
4440
Set-Item -Path "DellSmbios:\$($using:BIOSPath)" -value $using:BIOSValue
4541
}
4642
}
4743
Default {
4844
Write-Warning "No Method has been set. If you are running this outside of a maintenance session, uncomment the line that includes `$method"
4945
}
50-
}
46+
}

Function/Set-ScheduledTask.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function Test-ScheduledTaskScript {
3636
} else {
3737
# The contents are not identical
3838
$Test_ScheduledTaskScript_result = $false
39-
Write-Host "Script on Machine:"
39+
Write-Host "Script on Machine:"
4040
Write-Host $CurrentScriptContent
4141
Write-Host "Scripts NOT identical... Proceeding to next step"
4242
}
@@ -48,7 +48,7 @@ function Set-ScheduledTaskScript {
4848
Write-Warning "Script did not pass validation, configuring!"
4949
$Set_ScheduledTaskScript_result = Invoke-ImmyCommand {
5050
if(-not (test-path $using:scriptDir)){
51-
New-Item -Path $using:scriptDir -ItemType Directory | Out-Null
51+
New-Item -Path $using:scriptDir -ItemType Directory | Out-Null
5252
}
5353
New-Item $using:scriptPath -Value $using:ScriptContent -force
5454
}
@@ -89,7 +89,7 @@ switch ($method) {
8989

9090
# Pass the params to the machine directly and build the task
9191
if(!$Test_ScriptResult){
92-
$Set_ScriptResult = Set-ScheduledTaskScript
92+
$null = Set-ScheduledTaskScript
9393
Write-Progress -Activity "Setting Scheduled Task" -CurrentOperation "Enforced configured scriptblock" -PercentComplete 50 -Id 2
9494
}
9595
$result = Invoke-ImmyCommand {
@@ -124,4 +124,4 @@ switch ($method) {
124124
Write-Host "INFO: Scheduled Task Results:"
125125
return $result
126126
}
127-
}
127+
}

Function/WinFeatureShould-Be.ps1

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ switch ($method) {
1212
}
1313
"test" {
1414
$Current_Feature_State = Invoke-ImmyCommand { $feature = Get-WindowsOptionalFeature -FeatureName $using:Feature -Online; [string]$feature.State }
15-
$Feature_Test = ($Current_Feature_State -eq $State)
15+
$Feature_Test = ($Current_Feature_State -eq $State)
1616
return $Feature_Test
1717
}
1818
"set" {
1919
If ($State -eq 'Disabled') {
20-
Invoke-ImmyCommand { $result = Disable-WindowsOptionalFeature -Online -FeatureName $using:Feature; return $result }
21-
Write-Host "$Feature has been disabled."
20+
Invoke-ImmyCommand -Timeout 600 { $result = Disable-WindowsOptionalFeature -Online -FeatureName $using:Feature; return $result }
21+
Write-Host "$Feature has been $State."
22+
Restart-ComputerAndWait
2223
} elseif ($State -eq 'Enabled') {
23-
Invoke-ImmyCommand { $result = Enable-WindowsOptionalFeature -Online -FeatureName $using:Feature -all; return $result }
24-
Write-Host "$Feature has been disabled."
24+
Invoke-ImmyCommand -Timeout 600 { $result = Enable-WindowsOptionalFeature -Online -FeatureName $using:Feature -all -norestart; return $result }
25+
Write-Host "$Feature has been $State."
26+
Restart-ComputerAndWait
2527
} else {
26-
Write-Host "$Feature has already been disabled."
28+
Write-Host "$Feature has already been $State."
2729
}
2830
}
29-
}
31+
}

Integration/Dynamic Integration Type - Agent Smith.ps1

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ $Integration | Add-DynamicIntegrationCapability -Interface ISupportsListingClien
7373
$Integration | Add-DynamicIntegrationCapability -Interface ISupportsListingAgents -GetAgents {
7474
[CmdletBinding()]
7575
[OutputType([IProviderAgentDetails[]])]
76-
param(
77-
[Parameter(Mandatory)]
78-
[string[]]$clientIds
79-
)
76+
param()
8077
Import-Module AgentSmithAPI
8178

8279
$currentTime = Get-Date
@@ -109,10 +106,7 @@ $Integration | Add-DynamicIntegrationCapability -Interface ISupportsInventoryIde
109106
$Integration | Add-DynamicIntegrationCapability -Interface ISupportsDynamicVersions -GetDynamicVersions {
110107
[CmdletBinding()]
111108
[OutputType([Immybot.Backend.Domain.Models.DynamicVersion[]])]
112-
param(
113-
[Parameter(Mandatory=$True)]
114-
[System.String]$externalClientId
115-
)
109+
param()
116110

117111
$version = Get-DynamicVersionsFromGitHubUrl `
118112
-GitHubReleasesUrl "$($IntegrationContext.SmithGitRepoURL)/releases" `
@@ -123,10 +117,7 @@ $Integration | Add-DynamicIntegrationCapability -Interface ISupportsDynamicVersi
123117
$Integration | Add-DynamicIntegrationCapability -Interface ISupportsTenantInstallToken -GetTenantInstallToken {
124118
[CmdletBinding()]
125119
[OutputType([System.String])]
126-
param(
127-
[Parameter(Mandatory=$true)]
128-
[string]$clientId
129-
)
120+
param()
130121
$properties = @{
131122
secret = $IntegrationContext.SmithRegistrationSecret
132123
webhook = $IntegrationContext.SmithRegistrationWebhook

Task/Clean up mapped drives.ps1

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<#
2+
Author: Logan Cook
3+
Notes: Combined script with in-script parameters. This script will remove any network drives that are not in the list of permitted drives. This script will also set a pending reboot flag if any drives are removed.
4+
#>
5+
6+
param (
7+
[Parameter(Position=0,HelpMessage='Enter drive letters in the format of `R:`, then hit add.')]
8+
[string[]]$PermittedDrives
9+
)
10+
11+
$networkDrives = Invoke-ImmyCommand -Context "User" {
12+
# Switched from deprecated Get-WmiObject to Get-CimInstance (WS-Man & CIM standard compliant)
13+
try {
14+
$result = Get-CimInstance -ClassName Win32_NetworkConnection -ErrorAction Stop
15+
return $result
16+
}
17+
catch {
18+
Write-Error "Failed to retrieve network connections via CIM: $_"
19+
@() # Return empty collection on failure to avoid null reference issues later
20+
}
21+
}
22+
23+
switch($method){
24+
"test"{
25+
Invoke-ImmyCommand -Context "User" {
26+
$allPermitted = $true
27+
foreach ($drive in $using:networkDrives) {
28+
if ($using:PermittedDrives -notcontains $drive.LocalName) {
29+
$allPermitted = $false
30+
Write-Host "Non-permitted network drive found:" $drive.LocalName
31+
} else {
32+
Write-Host "Permitted network drive found:" $drive.LocalName
33+
}
34+
}
35+
return $allPermitted
36+
}
37+
}
38+
"set"{
39+
Write-Host "Enforcing permitted network drives: $PermittedDrives"
40+
Invoke-ImmyCommand -Context "User" {
41+
foreach ($drive in $using:networkDrives) {
42+
if ($using:PermittedDrives -notcontains $drive.LocalName) {
43+
# Remove the network drive
44+
Remove-PSDrive -Name $drive.LocalName.Substring(0, 1) -Force
45+
Write-Host "Removed non-permitted network drive:" $drive.LocalName
46+
$pendingReboot = $true
47+
}
48+
}
49+
if ($pendingReboot -eq $true) {
50+
Set-PendingRebootFlag
51+
}
52+
if($pendingReboot -and $RebootPreference -ne "Suppress") {
53+
Write-Host "Restarting to clear mapped drive references."
54+
Restart-ComputerAndWait
55+
}
56+
}
57+
}
58+
}

Task/Enable WinRM Combined Script.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
switch($method) {
22
"test" {
3-
Invoke-ImmyCommand {
3+
Invoke-ImmyCommand {
44
Try{
55
Test-WSMan -Authentication Default -ErrorAction Stop | Out-Null
66
return $true
@@ -10,8 +10,8 @@ switch($method) {
1010
}
1111
}
1212
"set" {
13-
Invoke-ImmyCommand {
14-
WinRM quickconfig -force
13+
Invoke-ImmyCommand {
14+
WinRM quickconfig -force
1515
}
1616
}
1717
default {

Task/Map Azure Drive Combined Script.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Enter your storage Access Key or password.
88
'@)]
99
[Password()]$accessKey,
1010
[Parameter(Position=2,Mandatory=$True,HelpMessage=@'
11-
Array of drives to map at logon. Format is as follows:
11+
Array of drives to map at logon. Format is as follows:
1212
| Name | Value |
1313
|--------------|-------|
1414
| `appshares` | `Q` |

0 commit comments

Comments
 (0)