Skip to content

Commit 409d736

Browse files
committed
Merged scripts
1 parent 189b7d4 commit 409d736

16 files changed

+239
-194
lines changed

PSConfigFile/Public/Add-CommandToPSConfigFile.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
.AUTHOR Pierre Smit
99
10-
.COMPANYNAME Private
10+
.COMPANYNAME HTPCZA Tech
1111
1212
.COPYRIGHT
1313
@@ -44,6 +44,14 @@ Updated [13/11/2021_16:30] Added Function Script
4444

4545

4646

47+
<#
48+
49+
.DESCRIPTION
50+
Add a command to the config file
51+
52+
#>
53+
54+
4755
<#
4856
.SYNOPSIS
4957
Adds a named command or script block to the PSConfigFile configuration to be executed automatically when the config is invoked.

PSConfigFile/Public/Add-CredentialToPSConfigFile.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
.AUTHOR Pierre Smit
99
10-
.COMPANYNAME Private
10+
.COMPANYNAME HTPCZA Tech
1111
1212
.COPYRIGHT
1313
@@ -33,6 +33,14 @@ Created [21/05/2022_03:47] Initial Script Creating
3333
#>
3434

3535

36+
<#
37+
38+
.DESCRIPTION
39+
Creates a self signed cert, then uses it to securely save a credential to the config file.
40+
41+
#>
42+
43+
3644
<#
3745
.SYNOPSIS
3846
Securely saves a credential to the PSConfigFile configuration using a self-signed certificate for encryption.

PSConfigFile/Public/Add-FunctionToPSConfigFile.ps1

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
.AUTHOR Pierre Smit
99
10-
.COMPANYNAME Private
10+
.COMPANYNAME HTPCZA Tech
1111
1212
.COPYRIGHT
1313
@@ -36,6 +36,15 @@ Updated [18/11/2021_08:31] Changed the update script to Set-PSConfigFileExecutio
3636

3737

3838

39+
<#
40+
41+
.DESCRIPTION
42+
Add Function to the config file.
43+
44+
#>
45+
46+
47+
3948
<#
4049
.SYNOPSIS
4150
Adds a named PowerShell function (shortcut) to the PSConfigFile configuration.
@@ -140,14 +149,4 @@ function Add-FunctionToPSConfigFile {
140149
Write-Host "ConfigFile: $($confile.FullName)" -ForegroundColor Cyan
141150
} catch { Write-Error "Error: `n $_" }
142151
} #end Function
143-
Rename-Item -Path $confile -NewName "Outdated_PSConfigFile_$(Get-Date -Format yyyyMMdd_HHmm)_$(Get-Random -Maximum 50).xml" -Force
144-
Write-Host 'Original ConfigFile Renamed' -ForegroundColor Yellow
145-
}
146-
$Update | Export-Clixml -Depth 10 -Path $confile.FullName -NoClobber -Encoding utf8 -Force
147-
Write-Host 'Function Added: ' -ForegroundColor Green -NoNewline
148-
Write-Host "$($FunctionName)" -ForegroundColor Yellow
149-
Write-Host "ConfigFile: $($confile.FullName)" -ForegroundColor Cyan
150-
} catch { Write-Error "Error: `n $_" }
151152

152-
153-
} #end Function

PSConfigFile/Public/Add-LocationToPSConfigFile.ps1

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,44 @@
77
88
.AUTHOR Pierre Smit
99
10-
.COMPANYNAME Private
10+
.COMPANYNAME HTPCZA Tech
1111
1212
.COPYRIGHT
1313
1414
.TAGS powershell ps
1515
16+
.LICENSEURI
17+
18+
.PROJECTURI
19+
20+
.ICONURI
21+
22+
.EXTERNALMODULEDEPENDENCIES
23+
24+
.REQUIREDSCRIPTS
25+
26+
.EXTERNALSCRIPTDEPENDENCIES
27+
28+
.RELEASENOTES
29+
Created [04/10/2021_19:06] Initial Script Creating
30+
Updated [05/10/2021_08:30] Spit into more functions
31+
Updated [08/10/2021_20:51] Getting ready to upload
32+
Updated [14/10/2021_19:32] Added PSDrive Script
33+
Updated [13/11/2021_16:30] Added Function Script
34+
35+
.PRIVATEDATA
36+
37+
#>
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
<#
1648
1749
.DESCRIPTION
1850
Add a start-up location to the config file
@@ -21,7 +53,6 @@ Add a start-up location to the config file
2153

2254

2355

24-
2556
<#
2657
.SYNOPSIS
2758
Adds a default start-up location (folder or PSDrive) to the PSConfigFile configuration.
Lines changed: 7 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
<#PSScriptInfo
23
34
.VERSION 0.1.0
@@ -6,7 +7,7 @@
67
78
.AUTHOR Pierre Smit
89
9-
.COMPANYNAME Private
10+
.COMPANYNAME HTPCZA Tech
1011
1112
.COPYRIGHT
1213
@@ -31,145 +32,12 @@ Created [18/08/2022_07:54] Initial Script Creating
3132
3233
#>
3334

34-
<#
35-
.SYNOPSIS
36-
Adds a default parameter value for a function to the PSConfigFile configuration.
37-
38-
.DESCRIPTION
39-
This function allows you to specify default parameter values for any PowerShell function. These defaults are stored in your configuration file and will be automatically applied in your session, saving you from repeatedly specifying common parameters. Wildcards can be used to apply defaults to multiple functions or parameters.
40-
41-
.PARAMETER Function
42-
The name of the function to add a default parameter for. Wildcards are supported to match multiple functions.
43-
44-
.PARAMETER Parameter
45-
The name of the parameter to set a default value for. Wildcards are supported to match multiple parameters.
46-
47-
.PARAMETER Value
48-
The value to assign as the default for the specified parameter.
49-
50-
.PARAMETER Force
51-
If specified, the config file will be deleted before saving the new one. If not specified and a config file exists, it will be renamed as a backup before saving the new version.
52-
53-
.EXAMPLE
54-
Add-PSDefaultParameterToPSConfigFile -Function Start-PSLauncher -Parameter PSLauncherConfigFile -Value C:\\temp\\PSLauncherConfig.json
55-
Sets a default value for the 'PSLauncherConfigFile' parameter of the 'Start-PSLauncher' function.
56-
57-
.EXAMPLE
58-
Add-PSDefaultParameterToPSConfigFile -Function *-Item -Parameter Path -Value C:\\Data -Force
59-
Sets a default 'Path' for all functions ending with '-Item', overwriting the config file if it exists.
60-
61-
.NOTES
62-
Author: Pierre Smit
63-
Website: https://smitpi.github.io/PSConfigFile
64-
Use this to streamline your PowerShell workflow with persistent default parameters.
65-
#>
66-
function Add-PSDefaultParameterToPSConfigFile {
67-
[Cmdletbinding(HelpURI = 'https://smitpi.github.io/PSConfigFile/Add-PSDefaultParameterToPSConfigFile')]
68-
[OutputType([System.Object[]])]
69-
param(
70-
[Parameter(Position = 0, Mandatory = $true, HelpMessage = 'Name of a function to add, You can use wildcards to apply to more functions.')]
71-
[string]$Function,
72-
[Parameter(Position = 1, Mandatory = $true, HelpMessage = 'Name of a parameter to add, You can use wildcards to apply to more parameters.')]
73-
[string]$Parameter,
74-
[Parameter(Position = 2, Mandatory = $true, HelpMessage = 'The Value to add.')]
75-
[string]$Value,
76-
[switch]$Force
77-
)
78-
79-
try {
80-
$confile = Get-Item $PSConfigFile -ErrorAction stop
81-
} catch {
82-
Add-Type -AssemblyName System.Windows.Forms
83-
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ Filter = 'XML | *.xml' }
84-
$null = $FileBrowser.ShowDialog()
85-
$confile = Get-Item $FileBrowser.FileName
86-
}
87-
88-
$XMLData = Import-Clixml -Path $confile.FullName
89-
$userdata = [PSCustomObject]@{
90-
Owner = $XMLData.Userdata.Owner
91-
CreatedOn = $XMLData.Userdata.CreatedOn
92-
PSExecutionPolicy = $XMLData.Userdata.PSExecutionPolicy
93-
Path = $XMLData.Userdata.Path
94-
Hostname = $XMLData.Userdata.Hostname
95-
PSEdition = $XMLData.Userdata.PSEdition
96-
OS = $XMLData.Userdata.OS
97-
BackupsToKeep = $XMLData.Userdata.BackupsToKeep
98-
ModifiedData = [PSCustomObject]@{
99-
ModifiedDate = [datetime](Get-Date)
100-
ModifiedAction = "Add PSDefaultParameter $($Function):$($Parameter)"
101-
}
102-
}
103-
[System.Collections.generic.List[PSObject]]$PSDefaultObject = @()
104-
if ([string]::IsNullOrEmpty($XMLData.PSDefaults)) {
105-
[void]$PSDefaultObject.Add([PSCustomObject]@{
106-
Name = "$($Function):$($Parameter)"
107-
Value = $Value
108-
})
109-
} else {
110-
$XMLData.PSDefaults | ForEach-Object {[void]$PSDefaultObject.Add($_)}
111-
[void]$PSDefaultObject.Add([PSCustomObject]@{
112-
Name = "$($Function):$($Parameter)"
113-
Value = $Value
114-
})
115-
}
116-
$Update = [psobject]@{
117-
Userdata = $Userdata
118-
PSDrive = $XMLData.PSDrive
119-
PSFunction = $XMLData.PSFunction
120-
PSCreds = $XMLData.PSCreds
121-
PSDefaults = ($PSDefaultObject | Where-Object {$_ -notlike $null})
122-
SetLocation = $XMLData.SetLocation
123-
SetVariable = $XMLData.SetVariable
124-
Execute = $XMLData.Execute
125-
}
126-
try {
127-
if ($force) {
128-
Remove-Item -Path $confile.FullName -Force -ErrorAction Stop
129-
Write-Host 'Original ConfigFile Removed' -ForegroundColor Red
130-
} else {
131-
Rename-Item -Path $confile -NewName "Outdated_PSConfigFile_$(Get-Date -Format yyyyMMdd_HHmm)_$(Get-Random -Maximum 50).xml" -Force
132-
Write-Host 'Original ConfigFile Renamed' -ForegroundColor Yellow
133-
}
134-
$Update | Export-Clixml -Depth 10 -Path $confile.FullName -NoClobber -Encoding utf8 -Force
135-
Write-Host 'PSDefault Added: ' -ForegroundColor Green -NoNewline
136-
Write-Host "$($Function):$($Parameter)" -ForegroundColor Yellow
137-
Write-Host "ConfigFile: $($confile.FullName)" -ForegroundColor Cyan
138-
} catch { Write-Error "Error: `n $_" }
139-
} #end Function
140-
141-
<#PSScriptInfo
142-
143-
.VERSION 0.1.0
144-
145-
.GUID 4a597ee8-f395-4479-9f80-1730b90e0eaf
146-
147-
.AUTHOR Pierre Smit
148-
149-
.COMPANYNAME Private
150-
151-
.COPYRIGHT
152-
153-
.TAGS ps
154-
155-
.LICENSEURI
35+
<#
15636
157-
.PROJECTURI
37+
.DESCRIPTION
38+
Add PSDefaultParameterValues to the config file
15839
159-
.ICONURI
160-
161-
.EXTERNALMODULEDEPENDENCIES
162-
163-
.REQUIREDSCRIPTS
164-
165-
.EXTERNALSCRIPTDEPENDENCIES
166-
167-
.RELEASENOTES
168-
Created [18/08/2022_07:54] Initial Script Creating
169-
170-
.PRIVATEDATA
171-
172-
#>
40+
#>
17341

17442
<#
17543
.SYNOPSIS
@@ -277,3 +145,4 @@ function Add-PSDefaultParameterToPSConfigFile {
277145
Write-Host "ConfigFile: $($confile.FullName)" -ForegroundColor Cyan
278146
} catch { Write-Error "Error: `n $_" }
279147
} #end Function
148+

PSConfigFile/Public/Add-PSDriveToPSConfigFile.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
<#PSScriptInfo
23
34
.VERSION 1.0.2
@@ -6,7 +7,7 @@
67
78
.AUTHOR Pierre Smit
89
9-
.COMPANYNAME Private
10+
.COMPANYNAME HTPCZA Tech
1011
1112
.COPYRIGHT
1213
@@ -37,6 +38,14 @@ Updated [13/11/2021_16:30] Added Function Script
3738

3839

3940

41+
<#
42+
43+
.DESCRIPTION
44+
Add PSDrive to the config file
45+
46+
#>
47+
48+
4049
<#
4150
.SYNOPSIS
4251
Adds an existing PSDrive to the PSConfigFile configuration for automatic session setup.
@@ -133,3 +142,4 @@ function Add-PSDriveToPSConfigFile {
133142
} catch { Write-Error "Error: `n $_" }
134143
} #end Function
135144

145+

PSConfigFile/Public/Add-VariableToPSConfigFile.ps1

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
<#PSScriptInfo
23
34
.VERSION 1.1.4
@@ -6,7 +7,7 @@
67
78
.AUTHOR Pierre Smit
89
9-
.COMPANYNAME Private
10+
.COMPANYNAME HTPCZA Tech
1011
1112
.COPYRIGHT
1213
@@ -31,6 +32,14 @@
3132
3233
#>
3334

35+
<#
36+
37+
.DESCRIPTION
38+
Adds variable to the config file.
39+
40+
#>
41+
42+
3443
<#
3544
.SYNOPSIS
3645
Adds one or more existing variables to the PSConfigFile configuration for automatic session import.
@@ -68,12 +77,12 @@ function Add-VariableToPSConfigFile {
6877
$confile = Get-Item $PSConfigFile -ErrorAction stop
6978
} catch {
7079
if ($IsWindows) {
71-
Add-Type -AssemblyName System.Windows.Forms
72-
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ Filter = 'XML | *.xml' }
73-
$null = $FileBrowser.ShowDialog()
74-
$confile = Get-Item $FileBrowser.FileName
80+
Add-Type -AssemblyName System.Windows.Forms
81+
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ Filter = 'XML | *.xml' }
82+
$null = $FileBrowser.ShowDialog()
83+
$confile = Get-Item $FileBrowser.FileName
7584
} else {
76-
Write-Error "No valid Config file found."
85+
Write-Error 'No valid Config file found.'
7786
exit
7887
}
7988
}
@@ -146,3 +155,4 @@ $scriptblock = {
146155
Get-Variable | Where-Object {$_.Name -like "$wordToComplete*"} | ForEach-Object {"$($_.name)"}
147156
}
148157
Register-ArgumentCompleter -CommandName Add-VariableToPSConfigFile -ParameterName VariableNames -ScriptBlock $scriptBlock
158+

0 commit comments

Comments
 (0)