shell - Using a text file as input to a Powershell script -


my group moving new network can't directly copy our computer in network new machine in network b. after years on machine in network a, i've got project files interspersed on disk. need build script copy folders , files backup disk. no problem there, network tech guy requires total byte count known before copying.

in cmd i've used dir /ad /s /b > c:\users\r6540\desktop\userfiles.txt c:\ generate huge list of directories, including lot of junk i've manually edited out.

e.g.

c:\dev\ssis c:\dev\ssis\databasecleanup c:\dev\ssis\databasemainttests c:\dev\ssis\eclipsekeys c:\dev\ssis\templateproject 

i've never used powershell, looks task within ability. found this:

$startfolder = "c:\scripts"  $colitems = (get-childitem $startfolder | measure-object -property length -sum) "$startfolder -- " + "{0:n2}" -f ($colitems.sum / 1mb) + " mb"  $colitems = (get-childitem $startfolder -recurse | where-object {$_.psiscontainer -eq $true} | sort-object) foreach ($i in $colitems)     {         $subfolderitems = (get-childitem $i.fullname | measure-object -property length -sum)         $i.fullname + " -- " + "{0:n2}" -f ($subfolderitems.sum / 1mb) + " mb"     } 

at microsoft technet , this, same page:

$objfso = new-object -com  scripting.filesystemobject "{0:n2}" -f (($objfso.getfolder("c:\scripts").size) / 1mb) + " mb" 

the output i'm looking directory name, tab, , folder size (without "mb" shown above though) , crlf eol written text file.

e.g.

c:\dev\ssis 70.23 c:\dev\ssis\databasecleanup 17.80 c:\dev\ssis\databasemainttests  22.91 c:\dev\ssis\eclipsekeys 1.22 c:\dev\ssis\templateproject 13.29 

anyone know powershell enough troop through userfiles.txt , resulting text file output?

form doesn't matter as function--so if can come alternate approach, i'd glad see it.

thanks.

this pretty straightforward in powershell:

$objfso = new-object -com  scripting.filesystemobject get-content c:\input.txt |     foreach { "{0}`t{1:n2}" -f $_, (($objfso.getfolder($_).size) / 1mb) } |     out-file c:\output.txt -enc ascii 

this assuming filesystemobject script found works. :-)


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -