Powershell use Get-ChildItem

Posted on 2009-12-30
Last Modified: 2013-12-07
I need to clean data out of my IIs logs before webtrends processes them.  How can I pass the Get-ChildItem -Name results into an array and then run the following command against each item in the array?

(Type $ChildItemVariable1.log) -Notwith "" | Out-File $ChildItemVariable1.log
Question by:ThatVaiGuy
    LVL 70

    Accepted Solution


    Hmmm... -NotWith?


    $Dir = "C:\Whatever"
    ForEach ($File in (Get-ChildItem $Dir)
      (Type $File.Name) -NotWith "" | Out-File $File.Name

    Not entirely clear what you're doing to the file, so that simply encapsulates the command in a very simple loop.

    LVL 1

    Author Comment

    Sorry, that should have read "-notmatch".  I kept thinking it was -notwith yesterday, but that parameter is not valid.  Forgive me, It was an error on my part.
    LVL 1

    Author Closing Comment

    Chris-Dent is right that the parameter -notwith is incorrect.  the correct parameter to use is -notmatch.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 for Beginning Beginners

    Are you looking for an efficient introduction to HTML5? Have you tried other HTML5 courses and found them too complex? Do you need just the basics of HTML5 to use with Wordpress or other content management system? If you said yes to any of these questions, this course is for you.

    How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now