Replacing the foreach loop with the foreach-object cmdlet