Skip to content

Commit 8a48329

Browse files
committed
Before PS5 Removal.
1 parent 3ef79c6 commit 8a48329

19 files changed

Lines changed: 844 additions & 465 deletions

PSConfigFile/PSConfigFile.psd1

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: Pierre Smit
55
#
6-
# Generated on: 2022-09-18 17:55:59Z
6+
# Generated on: 3/1/2026
77
#
88

99
@{
@@ -12,7 +12,7 @@
1212
RootModule = 'PSConfigFile.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.1.36'
15+
ModuleVersion = '0.1.39'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -24,28 +24,28 @@ GUID = 'd1fff6c2-e0c4-49ba-8632-e0137d78151c'
2424
Author = 'Pierre Smit'
2525

2626
# Company or vendor of this module
27-
CompanyName = 'HTPCZA Tech'
27+
CompanyName = 'Private'
2828

2929
# Copyright statement for this module
3030
Copyright = '(c) 2021 Pierre Smit. All rights reserved.'
3131

3232
# Description of the functionality provided by this module
33-
Description = 'Creates a Config file with Variables, PSDrives, Credentials, Shortcuts(Functions), PSDefaultParameters and a Starting location. You can then execute this config when your profile is loaded, or you can run it manually at any time. And all of the variables, psdrives credentials ext. are then available in your session. This way you can quickly and easily switch between "environment setups"'
33+
Description = 'PSConfigFile is an extension to your PowerShell profile that enables advanced, portable, and modular environment management. It creates a configuration file containing Variables, PSDrives, Credentials, Shortcuts (Functions), PSDefaultParameters, and a Starting Location. You can execute this config automatically when your profile loads, or manually at any time, making all your environment settings instantly available in your session. Effortlessly switch between different environment setups, share configurations across systems, and keep your PowerShell experience consistent and efficient.'
3434

35-
# Minimum version of the Windows PowerShell engine required by this module
35+
# Minimum version of the PowerShell engine required by this module
3636
# PowerShellVersion = ''
3737

38-
# Name of the Windows PowerShell host required by this module
38+
# Name of the PowerShell host required by this module
3939
# PowerShellHostName = ''
4040

41-
# Minimum version of the Windows PowerShell host required by this module
41+
# Minimum version of the PowerShell host required by this module
4242
# PowerShellHostVersion = ''
4343

4444
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
4545
# DotNetFrameworkVersion = ''
4646

4747
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
48-
# CLRVersion = ''
48+
# ClrVersion = ''
4949

5050
# Processor architecture (None, X86, Amd64) required by this module
5151
# ProcessorArchitecture = ''
@@ -73,9 +73,10 @@ FunctionsToExport = 'Add-CommandToPSConfigFile', 'Add-CredentialToPSConfigFile',
7373
'Add-FunctionToPSConfigFile', 'Add-LocationToPSConfigFile',
7474
'Add-PSDefaultParameterToPSConfigFile', 'Add-PSDriveToPSConfigFile',
7575
'Add-VariableToPSConfigFile', 'Export-PSConfigFilePFX',
76-
'Import-PSConfigFilePFX', 'Invoke-PSConfigFile', 'New-PSConfigFile',
76+
'Import-PSConfigFilePFX', 'Invoke-PSConfigFile',
77+
'New-PSConfigCertificate', 'New-PSConfigFile',
7778
'Remove-ConfigFromPSConfigFile', 'Set-PSConfigFileExecution',
78-
'Show-PSConfigFile', 'Update-CredentialsInPSConfigFile'
79+
'Show-PSConfigFile', 'Update-PSConfigFileCredentials'
7980

8081
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
8182
CmdletsToExport = @()
@@ -113,7 +114,7 @@ PrivateData = @{
113114
# IconUri = ''
114115

115116
# ReleaseNotes of this module
116-
ReleaseNotes = 'Updated [18/09/2022_17:55] added auto remove of old backup files.'
117+
ReleaseNotes = 'Updated [01/03/2026_09:32] Removed show function'
117118

118119
# Prerelease string of this module
119120
# Prerelease = ''

PSConfigFile/Public/Add-CommandToPSConfigFile.ps1

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
.AUTHOR Pierre Smit
99
10-
.COMPANYNAME HTPCZA Tech
10+
.COMPANYNAME Private
1111
1212
.COPYRIGHT
1313
@@ -44,38 +44,38 @@ 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-
5547
<#
5648
.SYNOPSIS
57-
Adds a command or script block to the config file, to be executed every time the invoke function is called.
49+
Adds a named command or script block to the PSConfigFile configuration, to be executed automatically when the config is invoked.
5850
5951
.DESCRIPTION
60-
Adds a command or script block to the config file, to be executed every time the invoke function is called.
52+
Use this function to store custom commands or script blocks in your configuration file. These commands will be executed every time the config file is invoked using Invoke-PSConfigFile. This is useful for automating environment setup, running startup tasks, or ensuring certain commands always run in your PowerShell environment.
6153
6254
.PARAMETER ScriptBlockName
63-
Name for the script block
55+
The unique name to assign to the script block. This name is used to identify and manage the command within the config file.
6456
6557
.PARAMETER ScriptBlock
66-
The commands to be executed
58+
The PowerShell command(s) or script block to be executed. Provide as a string. Example: "Get-ChildItem C:\\Logs | Out-File C:\\log.txt"
6759
6860
.PARAMETER Force
69-
Will delete the config file before saving the new one. If false, then the config file will be renamed.
61+
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.
7062
63+
.EXAMPLE
64+
Add-CommandToPSConfigFile -ScriptBlockName DriveC -ScriptBlock "Get-ChildItem c:\\"
65+
Adds a script block named 'DriveC' that lists the contents of the C drive every time the config is invoked.
7166
7267
.EXAMPLE
73-
Add-CommandToPSConfigFile -ScriptBlockName DriveC -ScriptBlock "Get-ChildItem c:\"
68+
Add-CommandToPSConfigFile -ScriptBlockName Startup -ScriptBlock "Write-Host 'Welcome!'" -Force
69+
Adds a script block named 'Startup' that displays a welcome message, overwriting the config file if it exists.
7470
71+
.NOTES
72+
Author: Pierre Smit
73+
Website: https://smitpi.github.io/PSConfigFile
74+
This function is part of the PSConfigFile module for managing PowerShell configuration automation.
7575
#>
76-
Function Add-CommandToPSConfigFile {
76+
function Add-CommandToPSConfigFile {
7777
[Cmdletbinding(HelpURI = 'https://smitpi.github.io/PSConfigFile/Add-CommandToPSConfigFile')]
78-
PARAM(
78+
param(
7979
[ValidateNotNullOrEmpty()]
8080
[string]$ScriptBlockName,
8181
[ValidateNotNullOrEmpty()]
@@ -105,10 +105,7 @@ Function Add-CommandToPSConfigFile {
105105
BackupsToKeep = $XMLData.Userdata.BackupsToKeep
106106
ModifiedData = [PSCustomObject]@{
107107
ModifiedDate = [datetime](Get-Date)
108-
ModifiedUser = "$($env:USERNAME.ToLower())@$($env:USERDNSDOMAIN.ToLower())"
109108
ModifiedAction = "Added Command: $($ScriptBlockName)"
110-
Path = "$confile"
111-
Hostname = ([System.Net.Dns]::GetHostEntry(($($env:COMPUTERNAME)))).HostName
112109
}
113110
}
114111

PSConfigFile/Public/Add-CredentialToPSConfigFile.ps1

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
.AUTHOR Pierre Smit
99
10-
.COMPANYNAME HTPCZA Tech
10+
.COMPANYNAME Private
1111
1212
.COPYRIGHT
1313
@@ -33,40 +33,40 @@ 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-
4336
<#
4437
.SYNOPSIS
45-
Creates a self signed cert, then uses it to securely save a credential to the config file.
38+
Securely saves a credential to the PSConfigFile configuration using a self-signed certificate for encryption.
4639
4740
.DESCRIPTION
48-
Creates a self signed cert, then uses it to securely save a credential to the config file.
49-
You can export the cert, and install it on other machines. Then you would be able to decrypt the password on those machines.
41+
This function creates a self-signed certificate (if one does not already exist) and uses it to encrypt and store a PowerShell credential object in your configuration file. The certificate can be exported and installed on other machines, allowing you to decrypt and use the credential securely across trusted systems. This is ideal for automating scripts that require credentials without exposing sensitive information in plain text.
5042
5143
.PARAMETER Name
52-
This name will be used for the variable when invoke command is executed.
44+
The variable name to assign to the credential in the config file. This name is used to reference the credential when invoking commands from the config.
5345
5446
.PARAMETER Credential
55-
Credential object to be saved.
47+
The PowerShell credential object to be securely stored. Use Get-Credential to create this object.
5648
5749
.PARAMETER Force
58-
Will delete the config file before saving the new one. If false, then the config file will be renamed.
59-
50+
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.
6051
6152
.EXAMPLE
62-
$labcred = get-credential
53+
$labcred = Get-Credential
6354
Add-CredentialToPSConfigFile -Name LabTest -Credential $labcred
55+
Prompts for credentials and saves them securely in the config file under the name 'LabTest'.
56+
57+
.EXAMPLE
58+
Add-CredentialToPSConfigFile -Name AdminUser -Credential (Get-Credential) -Force
59+
Saves a credential named 'AdminUser', overwriting the config file if it exists.
6460
61+
.NOTES
62+
Author: Pierre Smit
63+
Website: https://smitpi.github.io/PSConfigFile
64+
Credentials are encrypted using a self-signed certificate for security and portability.
6565
#>
66-
Function Add-CredentialToPSConfigFile {
66+
function Add-CredentialToPSConfigFile {
6767
[Cmdletbinding(HelpURI = 'https://smitpi.github.io/PSConfigFile/Add-CredentialToPSConfigFile')]
6868
[OutputType([System.Object[]])]
69-
PARAM(
69+
param(
7070
[string]$Name,
7171
[pscredential]$Credential,
7272
[switch]$Force
@@ -90,13 +90,10 @@ Function Add-CredentialToPSConfigFile {
9090
Hostname = $XMLData.Userdata.Hostname
9191
PSEdition = $XMLData.Userdata.PSEdition
9292
OS = $XMLData.Userdata.OS
93-
BackupsToKeep = $XMLData.Userdata.BackupsToKeep
93+
BackupsToKeep = $XMLData.Userdata.BackupsToKeep
9494
ModifiedData = [PSCustomObject]@{
9595
ModifiedDate = [datetime](Get-Date)
96-
ModifiedUser = "$($env:USERNAME.ToLower())@$($env:USERDNSDOMAIN.ToLower())"
9796
ModifiedAction = "Added Credencial: $($Name)"
98-
Path = "$confile"
99-
Hostname = ([System.Net.Dns]::GetHostEntry(($($env:COMPUTERNAME)))).HostName
10097
}
10198
}
10299

@@ -129,7 +126,7 @@ Function Add-CredentialToPSConfigFile {
129126
$Edition = 'PSDesktop'
130127
$EncryptedBytes = $selfcert.PublicKey.Key.Encrypt($EncodedPwd, $true)
131128
} else {
132-
Write-Warning -Message 'Password is saved for PowerShell Core, rerun command in Windows PowerShell Core to save it in that edition as well.'
129+
Write-Warning -Message 'Password is saved for PowerShell Core, rerun command in Windows PowerShell to save it in that edition as well.'
133130
$Edition = 'PSCore'
134131
$EncryptedBytes = $selfcert.PublicKey.Key.Encrypt($EncodedPwd, [System.Security.Cryptography.RSAEncryptionPadding]::OaepSHA512)
135132
}
@@ -174,8 +171,8 @@ Function Add-CredentialToPSConfigFile {
174171
Write-Host 'Original ConfigFile Renamed' -ForegroundColor Yellow
175172
}
176173
$Update | Export-Clixml -Depth 10 -Path $confile.FullName -NoClobber -Encoding utf8 -Force
177-
Write-Host 'Credential Added: ' -ForegroundColor Green -NoNewline
178-
Write-Host "$($Name)" -ForegroundColor Yellow
174+
Write-Host 'Credential Added: ' -ForegroundColor Green -NoNewline
175+
Write-Host "$($Name)" -ForegroundColor Yellow
179176
Write-Host "ConfigFile: $($confile.FullName)" -ForegroundColor Cyan
180177
} catch { Write-Error "Error: `n $_" }
181178
} #end Function

PSConfigFile/Public/Add-FunctionToPSConfigFile.ps1

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

3939
<#
4040
41-
.DESCRIPTION
42-
Add Function to the config file.
43-
44-
#>
45-
46-
4741
<#
4842
.SYNOPSIS
49-
Creates Shortcuts (Functions) to commands or script blocks
43+
Adds a custom function (shortcut) to the PSConfigFile configuration for quick command or script execution.
5044
5145
.DESCRIPTION
52-
Creates Shortcuts (Functions) to commands or script blocks
46+
This function allows you to define named PowerShell functions (shortcuts) that execute specific commands or script blocks. These functions are stored in your configuration file and can be invoked automatically or manually, streamlining repetitive tasks and environment setup.
5347
5448
.PARAMETER FunctionName
55-
Name to use for the command
49+
The name to assign to the custom function. This is how you will reference and call the function from your config.
5650
5751
.PARAMETER CommandToRun
58-
Command to run in a string format
52+
The PowerShell command or script block (as a string) that the function will execute. Example: "Import-Module .\*.psm1 -Force -Verbose"
5953
6054
.PARAMETER Force
61-
Will delete the config file before saving the new one. If false, then the config file will be renamed.
55+
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.
6256
57+
.EXAMPLE
58+
Add-FunctionToPSConfigFile -FunctionName psml -CommandToRun "Import-Module .\*.psm1 -Force -Verbose"
59+
Adds a function named 'psml' that imports all PowerShell modules in the current directory with force and verbose options.
6360
6461
.EXAMPLE
65-
Add-FunctionToPSConfigFile -FunctionName psml -CommandToRun "import-module .\*.psm1 -force -verbose"
62+
Add-FunctionToPSConfigFile -FunctionName CleanLogs -CommandToRun "Remove-Item C:\\Logs\\* -Recurse -Force" -Force
63+
Adds a function named 'CleanLogs' to delete all log files, overwriting the config file if it exists.
6664
65+
.NOTES
66+
Author: Pierre Smit
67+
Website: https://smitpi.github.io/PSConfigFile
68+
Use this to automate and simplify common PowerShell tasks.
6769
#>
68-
Function Add-FunctionToPSConfigFile {
70+
function Add-FunctionToPSConfigFile {
6971
[Cmdletbinding(HelpURI = 'https://smitpi.github.io/PSConfigFile/Add-FunctionToPSConfigFile')]
70-
PARAM(
72+
param(
7173
[ValidateNotNullOrEmpty()]
7274
[string]$FunctionName,
7375
[ValidateNotNullOrEmpty()]
@@ -96,10 +98,7 @@ Function Add-FunctionToPSConfigFile {
9698
BackupsToKeep = $XMLData.Userdata.BackupsToKeep
9799
ModifiedData = [PSCustomObject]@{
98100
ModifiedDate = [datetime](Get-Date)
99-
ModifiedUser = "$($env:USERNAME.ToLower())@$($env:USERDNSDOMAIN.ToLower())"
100101
ModifiedAction = "Added Function: $($FunctionName)"
101-
Path = "$confile"
102-
Hostname = ([System.Net.Dns]::GetHostEntry(($($env:COMPUTERNAME)))).HostName
103102
}
104103
}
105104

0 commit comments

Comments
 (0)