July 2009 - Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

Welcome to the archive of tips delivered through Tobias' Tip of the Day RSS Feed and Your Power Tip of the Day email. Subscribe in the sidebar to get the latest tips!

Sort by: Most Recent | Most Viewed | Most Commented
  • Does a Folder contain a specific file?

    Test-Path supports wildcards so if you'd like to know whether there are any PowerShell script files located in your home folder, try this: Test-Path $home \ * . ps1 To get the actual number of PowerShell scripts, use Get-Childitem and count the result...
  • File Or Folder? Find Out!

    Test-Path can check whether a file or folder exists, but this does not tell you whether the path specified was actually a file or a folder. If you'd like to check whether the folder c:\test exists, use this: Test-Path c:\test -pathtype container If...
  • Test-Path Can Check More Than Files

    Test-Path is your friend whenever you want to check whether a file or folder exists: Test-Path C:\autoexec.bat Test-Path C:\windows Test-Path can check a lot of other things as well, though. It accepts any PowerShell drive, and as you may know, in PowerShell...
  • Creating A HTML Font List

    With just a couple of lines of code, you can create a HTML document listing each installed type face on your computer which you then can print out for reference. Next time you want to create a fancy newsletter or party invitation, grab your font reference...
  • Converting Objects Into Text

    PowerShell internally always works with objects, and this can cause confusion when you mix object and string technologies. In a previous example, you learned how to retrieve all font families like this: [ System.Reflection.Assembly ]:: LoadWithPartialName...
  • Listing All Installed Font Families

    To get a list of all available font families on your system, you can load the .NET drawing library and then ask the InstalledFontCollection for all font families: [ System.Reflection.Assembly ]:: LoadWithPartialName ( "System.Drawing" ) | Out...
  • Finding Empty Folders

    To find out all folders that contain no files, you can use this line: dir -recurse | Where-Object { $_ . PSIsContainer } | Where-Object { $_ . GetFiles (). Count -eq 0 } | ForEach-Object { $_ . FullName } It first retrieves all folders recursively and...
  • List All Folders and Subfolders

    Ever wanted to create a list of all folders and subfolders? It just takes one line: dir -recurse | Where-Object { $_ . PSIsContainer } | ForEach-Object { $_ . FullName } First, you list everything from your current location. To filter out only folders...
  • List Hidden Files

    Did you notice that Dir, ls or Get-ChildItem do not return hidden files? To see hidden files, you need to specify the -force parameter: Dir $env:windir -force But what if you just wanted to see hidden files only? Filter the result, for example like this...
  • Converting FileSystem To NTFS

    When you buy a new external USB drive, most of the time it is preformatted with the old FAT32 file system for compatibility reasons. You could reformat it with NTFS to enjoy more performance and better reliability but this will delete any data already...
  • Reading and Writing Drive Labels

    Drive Labels are the names attached to logical disks. Using WMI, you can both read and write (change) drive labels. To read the existing drive label, use this function: function Get-DriveLabel ( $letter = 'C:' ) { if ( ! ( Test-Path $letter )...
  • Finding Out A Drives' FileSystem

    If you ever needed a tool to find out the type of file system for any drive, take a look at this simple PowerShell function: function Get-FileSystem ( $letter = 'C:' ) { if ( ! ( Test-Path $letter )) { Throw "Drive $letter does not exist...
  • Feeding Input Into Native Commands

    Sometimes, you need to call commands that require interactive input to work. For example, to find out existing drives with DiskPart, you would have to start DiskPart and then interactively type the command: list disk A little known feature of PowerShells...
  • Advanced String Filtering

    In a previous tip, you learned how Select-String can filter string arrays based on a keyword. Have a look: route print | Select-String 127.0.0.1 However, when you look at the result, you may be surprised. It not only contains the filtered information...
  • Filtering Command Results

    PowerShell captures any output from any command you enter. This is why you can always store command results in a variable, even with native commands. Have a look: route print $result = route print In this case, $result now contains the result returned...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.