Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Find and Replace

Find and Replace

Find and Replace

I have a little problem when running this powershell script form a central location.  If i run from a central location i keep getting:-

Get-Content : Cannot bind argument to parameter 'Path' because it is null.


Set-Content : Cannot bind argument to parameter 'Path' because it is null.

If i run this within the $Dest lcation it works without errors, how can i get this script to run to change files?

$path = "K:\Business Systems\Microsoft Development\Deploy"
$Date = (get-date -uformat '%d%m%Y')
$DateTime = (get-date -uformat '%d/%m/%Y %H:%M:%S')
$Dest = "c:\testing\"
$LogCopy = "C:\testing\code_drop_FileCopy$Date.log"
$LogRename = "C:\testing\code_drop_RenameFiles$Date.log"
$LogRenameEtl = "C:\testing\code_drop_RenameEtl$Date.log"

write-output "$DateTime Logging started" | out-file -append $logrename
$configFiles=get-childitem $Dest *.config -recurse -verbose -force |  out-file -width "500" -append $logrename
foreach ($file in $configFiles)
(Get-Content $file.PSpath) | out-file -append $logrename

Foreach-Object {$_ -replace "%%DATABASE_SERVER%%", "SERVER"} |
Foreach-Object {$_ -replace "%%DATABASE_CATALOG%%", "DB"} |
Foreach-Object {$_ -replace "%%DATABASE_USER%%", "USER"} |
Foreach-Object {$_ -replace "%%DATABASE_PASSWORD%%", "PASSWORD"} |

Set-Content $file.PSpath -verbose | out-file -append $logrename
Write-host "$DateTime Files Amended" | out-file -append $logrename
write-output "$DateTime Logging Finished" | out-file -append $logrename

Any help would be appreciated.

RE: Find and Replace

Just an update to this, i have ran this in a powershell window and now what i get is:-

Get-Content : Access to the path ... is Denied

I think this is what is causing the arror above as it cannot get the contents.  How can i retreieve the contents of a folder that is in a different location from wher the script is running form?


RE: Find and Replace

I think the problem is your $configFiles=get-childitem... line. The Out-File cmdlet is an "end-of-line" cmdlet, it produces the file but doesn't pass along any objects through the pipeline. I think if you examine $configFiles after that statement you'll find it either empty or actually null since nothing gets assigned to it. Try splitting the line like this and see what happens


$configFiles = get-childitem $Dest *.config -recurse -verbose -force
$configFiles | out-file -width "500" -append $logrename
foreach ($file in $configFiles)

RE: Find and Replace

Hi, Thanks for the response, i had just found and then your post came through, yeah it's sending the content to log then not passing any of this on to the remainder of the script, hence Null.



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close