New to Powershell

by treaves04 at 2012-12-07 07:34:58

I am new to Powershell, this will be my first actual script in it. I have scripts in Excel that create PDF files based on certain cell value so that the name of the PDF actually gives my users most the info they need without having to open the actual file. My file names typically look like this: “Lot # - Community - Description.pdf” these files are produced in bulk across the course of a day and when created appear in the “My Documents” directory. Several times a week, I then have to move these files to a mapped network location based on the Lot # and Community Code for each file.

My Question is very simply, is this something Powershell can help me to automate? Can it look at the file name and see the lot and community and then match that to a directory with the same name at another location and move those files to that location? I am fairly certain it can and that this is not a difficult task, but I am not familar enough with Powershell yet to know which terms to search for to find examples to adapt to my needs. If someone can point me in the right direction, it will be most appreciated. Thanks in Advance.
by Klaas at 2012-12-07 07:50:54
If you really don’t know anything about Powershell I recommend you start by reading a book. Scroll to the top of this page to find a link in the right upper corner ‘books’.
You can find out everything about a command in the included help files by
Get-Help Move-Item -Full | More
The task you’re looking for can certainly be done. There are even different ways to do it, but you’ll have to start with some learning first.

May I also suggest you pick a relevant title for your upcoming posts? “New to Powershell” says nothing about the problem or question you’re struggling with. Try to be a bit more specific, please.
by RichardSiddaway at 2012-12-07 11:48:06
if you are new to PowerShell I would recommend the “PowerShell in a Month of Lunches” book as an excellent starting point
Do the hyphens actually appear in the file name? if so try something like this
## perform dir on your documents folder
Get-ChildItem -Path $home\Documents -Filter --*.pdf |
foreach { # loop through the pdfs
$array = $.BaseName -split “-” # split the file name at the hyphens: element 0 = Lot # & element 1 = Community
Move-Item -Path $
.FullName -Destination “\server\share$$($array[0])-$($array[1])” # move the file

Read the book in conjunction with this and hopefully you’ll be able to sort out any problems. Please post back any further questions