Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus


13 Free SQL Tools from Idera


Free Ebook: Mastering Powershell

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
  • Finding the Most Important Event Log Error Sources

    If you don't have much time yet would like to know what the most common sources of errors are in your System event log, try this line: Get-EventLog -LogName System -EntryType Error , Warning | Group-Object -Property Source | Sort-Object -Property...
  • Refresh Newly Mounted Disks

    If your script has just mounted a new drive, PowerShell may not immediately be able to access it (via Get-ChildItem, for example), because PowerShell did not yet update its drive list. To update the PowerShell drive list, run this: $null = Get-PSDrive...
  • Load Cmdlets from PSSnapins

    Most cmdlets these days are organized in modules. Modules were introduced in PowerShell 2.0. Their main advantage is copy&paste deployment (no installation required) and module auto-loading (PowerShell automatically loads modules when you need them...
  • Loading PowerShell Modules

    All cmdlets live in modules or snap-ins. To see which modules are currently loaded, use Get-Module. In PowerShell 3.0 or better, most modules are imported implicitly when you run a cmdlet found in that module. This clever mechanism implements a "load...
  • How to find Commands that have the Specified Parameter

    Get-Command is your primary tool when you need to find a command to accomplish something. You can search for verbs and/or nouns like this: # find all cmdlets/functions that stop things Get-Command -Verb Stop # find all cmdlets/functions that affect services...
  • Get CPU Cores and Processor Information

    WMI can find out details about your CPUs in just one line: PS> Get-WmiObject -Class Win32_Processor | Select-Object -Property Name, Number* Name NumberOfCores NumberOfLogicalProcessors ---- ------------- ------------------------- Intel(R) Core(TM)...
  • Installing Windows Features

    On servers, PowerShell can install Windows features with the cmdlet Install-WindowsFeature. When you save the result emitted by Install-WindowsFeature to a variable, you can view the install state after the change using Get-WindowsFeature: # install features...
  • Create Dynamic Script Blocks

    Script blocks are pieces of executable PowerShell code. You typically create them by enclosing code in braces. To dynamically create script blocks from inside your script, here is a way how you can turn a string into a script block. $scriptblock = [ ScriptBlock...
  • Manage NTFS Permission Inheritance

    By default, folders and files inherit permissions from their parents. To stop inheritance and make sure only the explicitly assigned permissions are valid, do two things: add the explicit permissions you need, and disable inheritance. This example creates...
  • Removing Explicit NTFS Permissions

    In previous examples, we showed you how you can add new NTFS permissions to an existing folder. If you want to reset permissions and make sure all previously present explicit NTFS permissions are removed, here is code that removes all existing permissions...
  • 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...
< Previous 1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.