I'm trying to figure out why, my Get-ChilddItem
variable is returning an empty $null value while running the below scriptblock, whereas from ISE, if i enter variables values manually, i'm able to get an output of the .sql files I've selected before the Get-ChildItem
command. Below is a beginning of the function i'm writing:
Function test{
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True]
[string]$client
)
# Define variables
$Master = 'master'
$Slave = 'slave'
$SourcePath = "C:\somefolder\folder"
$Masterfolder = "C:\somemasterfolder"
$Slavefolder = "C:\someslavefolder"
# Create folders
$clientdir2 = New-Item -Path $Slavefolder -name "$client" -ItemType Directory
# Create folder on secondary server
$clientdir = New-Item -Path "Microsoft.PowerShell.Core\FileSystem::\\$master\somemasterfolder" -name "$client" -ItemType Directory
# Getting all sql files and copy them to the destination folder
$gflz = Get-ChildItem $SourcePath\* -Include __07*, __08*, __10*
# Copy
Copy-Item $gflz $clientdir2
# Replace values in each sql files
$cpz = @(Get-ChildItem $clientdir2\* -Include *.sql)
if ($cpz -ne $null) {
Foreach ($flz in $cpz) {
(Get-Content $flz.FullName) | ForEach-Object { $_ -replace'clientID', "$client" -replace 'C:\LSpath', `
"$Masterfolder" -replace'C:\LSPath2', "$Slavefolder" } | Set-Content $flz.FullName}}
Thus, the replace operation cannot take place, as it loops on nothing. Am I writing this the wrong way for the intended purpose? Would you point me out to the right direction? Thanks!