PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Forum experts available to answer your PowerShell questions

Power Tips

Power Tips

Syndication

  • Getting Explicit NTFS Permissions

    To find out which NTFS access permissions have been assigned directly to a file or folder, check for the property "isInherited". This will create a new folder "sampleFolderNTFS", then list all explicit NTFS permissions. Since you just...
  • Managing NTFS Permissions

    In a previous tip we showed how you can add NTFS permission rules to a folder. To find out what kind of permissions are assignable, take a look at this: PS> [System.Enum]::GetNames([System.Security.AccessControl.FileSystemRights]) ListDirectory ReadData...
  • Create Folder with NTFS Permissions

    Often, you may need to create a new folder and also set NTFS permissions for the folder. Here is a simple example that creates a new folder and illustrates how you can add new permissions to the existing permissions: $Path = ' c:\protectedFolder '...
  • Splitting Long Lines

    To improve readability, you can break PowerShell lines into separate lines. Get-Service | Where-Object { $_ . Status -eq ' Running ' } Get-Service | Where-Object { $_ . Status -eq ' Running ' } After a pipeline symbol, you can always add...
  • Prompting for Function Parameters

    With a simple trick, you can add a dialog window that helps users to provide the function parameters for your function. Simply use $PSBoundParameters to determine if a user submitted parameters. If not, run Show-Command and submit the name of your function...
  • Using PowerShell’s Help Window for General Output

    To display text information, you can of course launch notepad.exe, and use the editor to display the text. Displaying text in an editor is not such a good idea, though, if you want to make sure the text cannot be changed. PowerShell comes with a great...
  • Playing Sound in the Background

    If your script takes some time to complete, you may want to play a system sound file. Here is a sample illustrating how this can be done: # find first available WAV file in Windows $WAVPath = Get-ChildItem -Path $env:windir -Filter * . wav -Recurse -ErrorAction...
  • Finding Executable

    Many file extensions are associated with executables. You can then use Invoke-Item to open a document with this executable. Finding out just which executable is responsible for a given file extension is not so trivial, though. You can read the Windows...
  • Splitting Text at Uppercase Letters

    To split a text at each uppercase letter, without having to provide a list of uppercase characters, try this example: $text = ' MapNetworkDriveWithCredential ' [ Char []] $raw = foreach ( $character in $text . ToCharArray ()) { if ([ Char ] :...
  • Finding Uppercase Characters

    If you'd like to find uppercase characters, you could use regular expressions. However, you would then provide a list of uppercase characters to check against. A more flexible way is to use the .NET function IsUpper(). Here is a sample: it scans a...
  • Using Green Checkmarks in Console Output

    In a previous tip you have seen that the PowerShell console supports all characters available in a TrueType font. You just need to convert the character code to the type "Char". Here is a more advanced example that uses splatting to insert a...
  • Using Symbols in Console Output

    Did you know that console output can contain special icons like checkmarks? All you need to do is set the console to a TrueType font like "Consolas". To display special characters, use the decimal or hexadecimal character code, for example:...
  • Test Nested Depth

    When you call a function, PowerShell increases the nest level. When a function calls another function, or script, this will again increase the nest level. Here is a function that can tell you the current nest level of your code: function Test-NestLevel...
  • Aborting Pipeline

    Sometimes you might want to abort a pipeline when a certain condition is met. Here is a creative way of doing this. It works all the way back to PowerShell 2.0. Take a look at the sample code: filter Stop-Pipeline { param ( [ scriptblock ] $condition...
  • "Continue" and Labels

    When you use the "Continue" statement inside a loop, you can skip the remainder of this loop iteration, and continue with the next. "Break" works similar, but aborts a loop and skips all remaining iterations. This raises the question...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.