Skip to content

Commit afef63b

Browse files
committed
Release 1.104.2025
1 parent 5f46dbe commit afef63b

8 files changed

Lines changed: 156 additions & 36 deletions

File tree

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,57 @@
11
################################################################################
2+
<#
3+
.SYNOPSIS
4+
Ensures that Pester testing framework is installed and available.
25
6+
.DESCRIPTION
7+
This function checks if Pester module is installed. If not found, it attempts to
8+
install it from the PowerShell Gallery and imports it into the current session.
9+
10+
.EXAMPLE
11+
AssurePester
12+
#>
313
function AssurePester {
414

5-
Import-Module -Name Pester -ErrorAction SilentlyContinue
15+
[CmdletBinding()]
16+
param()
617

7-
# Check if Pester is installed
8-
if (-not (Get-Module -Name Pester -ErrorAction SilentlyContinue)) {
18+
begin {
919

10-
Write-Host "Pester not found. Installing Pester..."
20+
Write-Verbose "Checking for Pester module installation..."
21+
}
1122

12-
# Install Pester from the PowerShell Gallery
13-
try {
14-
Install-Module -Name Pester -Force -SkipPublisherCheck | Out-Null
15-
Import-Module -Name Pester -Force | Out-Null
16-
Write-Host "Pester installed successfully."
17-
}
18-
catch {
23+
process {
24+
25+
# attempt to import pester module without showing errors
26+
Import-Module -Name Pester -ErrorAction SilentlyContinue
27+
28+
# check if pester module is available
29+
if (-not (Get-Module -Name Pester -ErrorAction SilentlyContinue)) {
30+
31+
Write-Verbose "Pester module not found, attempting installation..."
32+
Write-Host "Pester not found. Installing Pester..."
1933

20-
Write-Error "Failed to install Pester. Error: $PSItem"
34+
try {
35+
# install pester from powershell gallery
36+
$null = Install-Module -Name Pester -Force -SkipPublisherCheck
37+
38+
# import the newly installed module
39+
$null = Import-Module -Name Pester -Force
40+
41+
Write-Host "Pester installed successfully."
42+
Write-Verbose "Pester module installation and import completed."
43+
}
44+
catch {
45+
Write-Error "Failed to install Pester. Error: $PSItem"
46+
Write-Verbose "Pester installation failed with error."
47+
}
48+
}
49+
else {
50+
Write-Verbose "Pester module already installed and imported."
2151
}
2252
}
53+
54+
end {
55+
}
2356
}
57+
################################################################################

Functions/GenXdev.FileSystem/Expand-Path.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ function Expand-Path {
6363

6464
# normalize path separators and remove double separators
6565
$normalizedPath = $FilePath.Trim().Replace("\", [IO.Path]::DirectorySeparatorChar).
66-
Replace("/", [IO.Path]::DirectorySeparatorChar).
67-
Replace([IO.Path]::DirectorySeparatorChar + [IO.Path]::DirectorySeparatorChar,
68-
[IO.Path]::DirectorySeparatorChar)
66+
Replace("/", [IO.Path]::DirectorySeparatorChar)
6967

7068
# check if path ends with a directory separator
7169
$hasTrailingSeparator = $normalizedPath.EndsWith(

Functions/GenXdev.FileSystem/Find-Item.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ match within the content of each matched file.
1111
Specify the file name or pattern to search for. Default is "*".
1212
1313
.PARAMETER Pattern
14-
Specify the pattern to search within the files. Default is ".*".
14+
Regular expression pattern to search within the content of files to match against. Default is ".*".
1515
1616
.PARAMETER AllDrives
1717
Search all drives.
@@ -113,7 +113,7 @@ function Find-Item {
113113
Mandatory = $false,
114114
Position = 1,
115115
ParameterSetName = 'WithPattern',
116-
HelpMessage = "Regular expression pattern to search within matched files"
116+
HelpMessage = "Regular expression pattern to search within the content of files to match against"
117117
)]
118118
[Alias("mc", "matchcontent")]
119119
[PSDefaultValue(Value = ".*")]

Functions/GenXdev.FileSystem/Rename-InProject.ps1

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ function Rename-InProject {
6767
)
6868

6969
begin {
70-
# store original preferences for restoration
71-
$originalVerbosePreference = $VerbosePreference
72-
$originalWhatIfPreference = $WhatIfPreference
73-
7470
try {
7571
# normalize and validate source path
7672
$sourcePath = Expand-Path $Source
@@ -89,11 +85,6 @@ function Rename-InProject {
8985
Write-Verbose "Source path: $sourcePath"
9086
Write-Verbose "Search pattern: $searchPattern"
9187

92-
# enable verbose in whatif mode
93-
if ($WhatIfPreference -or $WhatIf) {
94-
$VerbosePreference = "Continue"
95-
}
96-
9788
# list of extensions to skip
9889
$skipExtensions = @(
9990
".jpg", ".jpeg", ".gif", ".bmp", ".png", ".tiff",
@@ -105,7 +96,6 @@ function Rename-InProject {
10596
}
10697
catch {
10798

108-
$WhatIfPreference = $originalWhatIfPreference
10999
throw
110100
}
111101
}

Functions/GenXdev.FileSystem/Start-RoboCopy.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,6 @@ Multiple overrides:
693693
[IO.Directory]::CreateDirectory($DestinationDirectory) | Out-Null
694694
}
695695

696-
# Turn on verbose
697-
$VerbosePreference = "Continue"
698-
699696
###############################################################################
700697

701698
function CurrentUserHasElivatedRights() {

GenXdev.FileSystem.psd1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
RootModule = 'GenXdev.FileSystem.psm1'
88

99
# Version number of this module.
10-
ModuleVersion = '1.102.2025'
10+
ModuleVersion = '1.104.2025'
1111

1212
# ID used to uniquely identify this module
1313
GUID = '2f62080f-0483-4421-8497-b3d433b65171'
@@ -34,7 +34,19 @@
3434
ClrVersion = '9.0.1'
3535

3636
# Functions 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 functions to export.
37-
FunctionsToExport = @("Start-RoboCopy", "Rename-InProject", "Expand-Path", "Find-Item", "Remove-AllItems", "Find-DuplicateFiles", "Move-ToRecycleBin", "Remove-OnReboot", "Move-ItemWithTracking", "Remove-ItemWithFallback", "AssurePester")
37+
FunctionsToExport = @(
38+
"AssurePester",
39+
"Expand-Path",
40+
"Find-DuplicateFiles",
41+
"Find-Item",
42+
"Move-ItemWithTracking",
43+
"Move-ToRecycleBin",
44+
"Remove-AllItems",
45+
"Remove-ItemWithFallback",
46+
"Remove-OnReboot",
47+
"Rename-InProject",
48+
"Start-RoboCopy"
49+
)
3850

3951
# 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.
4052
CmdletsToExport = @()
@@ -66,6 +78,7 @@
6678
".\\Functions\\GenXdev.FileSystem\\Remove-OnReboot.ps1",
6779
".\\Functions\\GenXdev.FileSystem\\Rename-InProject.ps1",
6880
".\\Functions\\GenXdev.FileSystem\\Start-RoboCopy.ps1",
81+
".\\Tests\\GenXdev.FileSystem\\Expand-Path.Tests.ps1",
6982
".\\Tests\\GenXdev.FileSystem\\Find-DuplicateFiles.Tests.ps1",
7083
".\\Tests\\GenXdev.FileSystem\\Find-Item.Tests.ps1",
7184
".\\Tests\\GenXdev.FileSystem\\Move-ItemWithTracking.Tests.ps1",

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Update-Module
7171
### GenXdev.FileSystem<hr/>
7272
| Command&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | aliases&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Description |
7373
| --- | --- | --- |
74-
| [AssurePester](#AssurePester) | | |
74+
| [AssurePester](#AssurePester) | | This function checks if Pester module is installed. If not found, it attempts toinstall it from the PowerShell Gallery and imports it into the current session. |
7575
| [Expand-Path](#Expand-Path) | ep | Expands any given file reference to a full pathname, with respect to the user'scurrent directory. Can optionally assure that directories or files exist. |
7676
| [Find-DuplicateFiles](#Find-DuplicateFiles) | fdf | Takes an array of directory paths, searches each path recursively for files,then groups files by name and optionally by size and modified date. Returnsgroups containing two or more duplicate files. |
7777
| [Find-Item](#Find-Item) | l | Searches for file- or directory- names, optionally performs a regular expressionmatch within the content of each matched file. |
@@ -96,13 +96,24 @@ Update-Module
9696
AssurePester
9797
````
9898

99+
### SYNOPSIS
100+
Ensures that Pester testing framework is installed and available.
101+
99102
### SYNTAX
100103
````PowerShell
101-
AssurePester
104+
AssurePester [<CommonParameters>]
102105
````
103106

107+
### DESCRIPTION
108+
This function checks if Pester module is installed. If not found, it attempts to
109+
install it from the PowerShell Gallery and imports it into the current session.
110+
104111
### PARAMETERS
105-
None
112+
<CommonParameters>
113+
This cmdlet supports the common parameters: Verbose, Debug,
114+
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
115+
OutBuffer, PipelineVariable, and OutVariable. For more information, see
116+
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
106117

107118
<br/><hr/><hr/><br/>
108119

@@ -247,7 +258,8 @@ Find-Item [[-SearchMask] <String>] [-AllDrives] [-Directory] [-PassThru]
247258
Aliases
248259
Accept wildcard characters? false
249260
-Pattern <String>
250-
Specify the pattern to search within the files. Default is ".*".
261+
Regular expression pattern to search within the content of files to match against.
262+
Default is ".*".
251263
Required? false
252264
Position? 2
253265
Default value .*
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
################################################################################
2+
3+
################################################################################
4+
5+
Describe "GenXdev.FileSystem\Expand-Path unit tests" {
6+
7+
BeforeAll {
8+
9+
# define test paths
10+
$Script:testPath = Join-Path $PSScriptRoot "TestData"
11+
$Script:testFile = Join-Path $Script:testPath "test.txt"
12+
}
13+
14+
It "expands relative path to absolute path" {
15+
# arrange
16+
$relativePath = ".\test.txt"
17+
Push-Location $Script:testPath
18+
19+
# act
20+
$result = Expand-Path $relativePath
21+
22+
# assert
23+
$result | Should -Be "$((Get-Location).Path)\test.txt"
24+
25+
# cleanup
26+
Pop-Location
27+
}
28+
29+
It "handles UNC paths" {
30+
# arrange
31+
$uncPath = "\\server\share\file.txt"
32+
33+
# act
34+
$result = Expand-Path $uncPath
35+
36+
# assert
37+
$result | Should -Be $uncPath
38+
}
39+
40+
It "preserves UNC paths exactly as provided" {
41+
# arrange
42+
$uncPath = "\\server\share\file.txt"
43+
44+
# act
45+
$result = Expand-Path $uncPath
46+
47+
# assert
48+
$result | Should -Be $uncPath
49+
}
50+
51+
It "preserves UNC paths with trailing slashes" {
52+
# arrange
53+
$uncPath = "\\webserver\sites\powershell.genxdev.net\"
54+
55+
# act
56+
$result = Expand-Path $uncPath
57+
58+
# assert
59+
$result | Should -Be "\\webserver\sites\powershell.genxdev.net"
60+
$result | Should -Not -Be "e:\webserver\sites\powershell.genxdev.net"
61+
$result | Should -Match "^\\\\[^\\]+"
62+
}
63+
64+
It "expands user home directory" {
65+
# arrange
66+
$homePath = "~/test.txt"
67+
68+
# act
69+
$result = Expand-Path $homePath
70+
71+
# assert
72+
$result | Should -Be (Join-Path $HOME "test.txt")
73+
}
74+
}
75+
76+
################################################################################

0 commit comments

Comments
 (0)