joining variables adds a Space
afternoon,
i've written first powershell script today looking @ others and works seperatly while testing when execute script have put in few write-host lines can see data being passed.
i noticed source location e:\cbt\staging \* instead of e:\cbt\staging\* there appears additional space, causes copy source wrong?
any ideas
# script name: movecbtdata.ps1 # created on: 02/07/2012 # author: mike lister # purpose: copy new \ updated cbt modules local offices #create array of servers $site = @("br","cr","cs","cv","ds","gl","hl","hq","la","lt","nw","pb","ph","tf","wa","wy") $servername = @("br cbt","cr cbt","cs cbt","cv cbt","ds cbt","gl cbt","hl cbt","hq cbt","la cbt","lt cbt","nw cbt","pb cbt","ph cbt","tf cbt","wa cbt","wy cbt") $sourcefiles = @("e:\cbt\staging\") #function check thier items in source locations or no need run function fnchecksourcefiles { $a = @(get-childitem $sourcefiles) if ($a.count) { write-host "number of files found in staging area:" $a.count #call function copy data servers fncopydata } else { write-host "there no files in staging area:" $a.count } } #function process files each server in array list. function fncopydata { #loop throug each of servers ($i = 0; $i -le $site.length -1; $i++) { write-host $site[$i] $basepath = "\\" + $site[$i] + "-cbtsvr1\" $donepath = $basepath + "localcbt\cbt\modules" if (test-path $donepath) { write-host "copying files for" $servername[$i] $fullsourcepath = $sourcepath + "*" write-host $fullsourcepath copy-item $fullsourcepath $donepath write-host "files copied" } else { write-host $donepath + " directory not exist" } } } #run functions fnchecksourcefiles
.: lister :.
if you're talking $sourcefiles, don't see how can change. way, initialise string, don't need wrap array.
this:
$sourcefiles = @("e:\cbt\staging\")
should simply:
$sourcefiles = "e:\cbt\staging\"
...although makes no material difference in case, it's important know types creating. code creates array single element. get-childitem accept array path, works, bear in mind. cast array when need one.
grant ward, a.k.a. bigteddy
Windows Server > Windows PowerShell
Comments
Post a Comment