forked from ligershark/template-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-replacer-sample.ps1
40 lines (33 loc) · 1.52 KB
/
file-replacer-sample.ps1
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
[cmdletbinding(SupportsShouldProcess=$true)]
param()
function Enable-GetNuGet{
[cmdletbinding()]
param($toolsDir = "$env:LOCALAPPDATA\LigerShark\tools\getnuget\",
$getNuGetDownloadUrl = 'https://raw.githubusercontent.com/sayedihashimi/publish-module/master/getnuget.psm1')
process{
if(!(get-module 'getnuget')){
if(!(Test-Path $toolsDir)){ New-Item -Path $toolsDir -ItemType Directory -WhatIf:$false }
$expectedPath = (Join-Path ($toolsDir) 'getnuget.psm1')
if(!(Test-Path $expectedPath)){
'Downloading [{0}] to [{1}]' -f $getNuGetDownloadUrl,$expectedPath | Write-Verbose
(New-Object System.Net.WebClient).DownloadFile($getNuGetDownloadUrl, $expectedPath)
if(!$expectedPath){throw ('Unable to download getnuget.psm1')}
}
'importing module [{0}]' -f $expectedPath | Write-Verbose
Import-Module $expectedPath -DisableNameChecking -Force -Scope Global
}
}
}
Enable-GetNuGet
'trying to load file replacer' | Write-Output
Enable-NuGetModule -name 'file-replacer' -version '0.2.0-beta'
$folder = pwd
$include = '*.txt'
# In case the script is in the same folder as the files you are replacing add it to the exclude list
$exclude = "$($MyInvocation.MyCommand.Name);"
$replacements = @{
'to-be-replaced'='replaced-with-this'
}
'replacing in files'|write-output
Replace-TextInFolder -folder $folder -include $include -exclude $exclude -replacements $replacements
'done replacing'|write-output