Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I've learned more from your forums in 3 days than 3 months at school and on the job combined..."

Geography

Where in the world do Tek-Tips members come from?
cumpleby (TechnicalUser)
23 Dec 11 4:07
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.

and

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.
 
cumpleby (TechnicalUser)
23 Dec 11 7:58
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?

Thanks
crobin1 (MIS)
23 Dec 11 10:02
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

CODE

$configFiles = get-childitem $Dest *.config -recurse -verbose -force
$configFiles | out-file -width "500" -append $logrename
foreach ($file in $configFiles)
...
 
cumpleby (TechnicalUser)
23 Dec 11 10:10
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.

Thanks

Chris

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!

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