New to Pester

I’ve been charged with converting a bash script running in cygwin to a powershell script. The goal of the script is to copy files that randomly drop into a directory, to another directory depending on the file name. I’ve got the basic idea of how I want my script to run. But I want to take this as a opportunity to learn/utilize pester.

I’m posting on the forum because I have no idea where to start on writing a test that ensures a file was copied from one directory, to the appropriate directory.

Use this for you Pester ramp up…

This week we are honored to have one of the authors of Pester here with us on the Hey, Scripting Guys! Blog. It's Dave Wyatt himself, a Cloud and Datacenter MVP. Dave, tell us all about Pester…

Note This is a five-part series that includes the following posts:
•What is Pester and Why Should I Care?
Learn about a new test framework for PowerShell called Pester
•Getting Started with Pester
Learn how to get information back from Pester
•Unit Testing PowerShell Code with Pester
Use Pester to analyze small pieces of Windows PowerShell code
•Testing Script Modules with Pester
Use Pester for testing PowerShell modules
•More Pester Features and Resources
Learn about more Pester resources

As for this…

The goal of the script is to copy files that randomly drop into a directory

… you can do this by building and using a WMI Event monitor to watch a folder for writes.

There are plenty of examples and articles on this topic. Use you search engine of choice to bring up a list.
‘wmi folder monitor’


Use PowerShell to Monitor for the Creation of New Files

Today I am going to develop a WMI event query to detect newly created files in a particular folder. Then I will use this WQL event query tomorrow to create a permanent WMI event consumer. In fact, whenever I am creating a permanent WMI event consumer, I always test it out as a temporary event consumer first. Creating a temporary event consumer with Windows PowerShell 2.0 is really easy, so it only makes sense to take this first step.

As for…

to another directory depending on the file name.

Use Get-ChildItem using a filter for the file names, the pipe that to the Copy-Item cmdlet to send to your destination.
Just look to the built-in PowerShell help files on their use.

    # Get parameters, examples, full and Online help for a cmdlet or function

    (Get-Command -Name Get-ChildItem).Parameters
    Get-help -Name Get-ChildItem -Examples
    Get-help -Name Get-ChildItem -Full
    Get-help -Name Get-ChildItem -Online

    (Get-Command -Name Copy-Item).Parameters
    Get-help -Name Copy-Item -Examples
    Get-help -Name Copy-Item -Full
    Get-help -Name Copy-Item -Online