O'Reilly logo

Windows Server® 2008 Administrator’s Companion by Charlie Russel and Sharon Crawford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Windows PowerShell Examples

Enough about theory and the basics of PowerShell. What we really wanted out of this chapter, after all, were some real-world examples. So, let’s take a look at some.

Typical File System Tasks

Two tasks a system administrator might need to do is search through a file system or directory for a particular file or for a particular string of text.

Let’s provide an example of each of these tasks. First, search for a particular filename:

PSH>Get-Childitem . -recurse|foreach-object{if($_.name -match
   "some"){$_.fullname}}
C:\demo\SOME-1.TXT
C:\demo\SOME-22.TXT
C:\demo\some_other.txt
C:\demo\other\something.txt

Here we get all the items in the current directory, recursively, and pipe the results to ForEach-Object, which iterates a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required