-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-String.ps1
More file actions
62 lines (55 loc) · 1.64 KB
/
Get-String.ps1
File metadata and controls
62 lines (55 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<#
.Synopsis
Search contents of PSD1 files for module property
configuration settings.
.DESCRIPTION
Searches given directory recursively for PSD1 files,
replaces a matched, captured regex pattern with
a given string. Allows a user to propegate a
change across a set of PowerShell Modules.
.INPUTS
This command has no pipeline input.
.OUTPUTS
Output from this cmdlet are objects containing information about the match(es).
.NOTES
This cmdlet pairs with the Set-String cmdlet.
#>
function Get-String
{
[CmdletBinding()]
[OutputType([PsCustomObject])]
Param
(
# Define the folder path
[Parameter(Mandatory=$true,
Position=0)]
[ValidateNotNull()]
[Alias("ExportFolder","Path")]
[string]
$Directory,
# Define the types of files to affect
[Parameter(Mandatory=$true,
Position=1)]
[ValidateNotNullOrEmpty()]
[string[]]
$FileTypes,
# Pattern to match [regex]
[Parameter(Mandatory=$true,
Position=2)]
[String]
$Pattern
)
Process {
# Prep the extention strings for comparison
$FileTypes = $FileTypes | ForEach-Object -Process {
$_ -replace '\.'
}
# Start with given folder path and recurse all ps1, psd1, psm1 files
$RecursedFiles = Get-ChildItem -Path $Directory -File -Recurse |
Where-Object {$FileTypes -contains ($_.Extension -replace '\.')}
$MatchedLines = $RecursedFiles | Select-String -Pattern $Pattern
}
End {
$MatchedLines
}
}