Idera nSoftware Compellent

Power Tips

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
  • Hide Error Messages

    You may already know that you can suppress error messages with the ErrorAction parameter, which is often a good idea. Take a look at this and then try the line with and without ErrorAction: dir $env:windir * . log -Recurse -ErrorAction SilentlyContinue...
  • Export CSV with Culture-Specific Delimiter

    Export-CSV used to only support the comma as separator, which caused problems on non-U.S.-systems. In PowerShell v.2, with -useCulture you can have Export-CSV use whatever delimiter is the right one, depending on your culture. There is only one caveat...
  • Stopping the Pipeline

    Usually, once a pipeline runs, you cannot stop it prematurely, even if you already received the information you were seeking. Simply use this filter to stop a pipeline: filter Stop-Pipeline ([ scriptblock ] $condition = { $true }) { $_ if ( & $condition...
  • Creating Large Dummy Files With .NET

    You can always resort to the underlying .NET framework whenever the functionality you need isn't available through a cmdlet. The following code is a very fast way to generate really large test files: $path = "$env:temp\testfile.txt" $file...
  • Creating Large Dummy Files

    Sometimes, it is more efficient to use existing console tools rather than PowerShell cmdlets. For example here is a way to create a large file for load tests: fsutil file createnew $env:temp \ dummy.bin (1gb) However, you should note that fsutil requires...
  • Running PowerShell Scripts as Scheduled Task

    If you have jobs that need to execute regularly, you can manage them with a PowerShell script and make it a scheduled task: schtasks / CREATE / TN CheckHealthScript / TR "powershell.exe ` -noprofile -executionpolicy Unrestricted ` -file %public%...
  • Launching a PowerShell Script Externally

    To launch a PowerShell script outside of the PowerShell console (i.e. as scheduled task or as a link), prepend the script path with this: Powershell.exe -noprofile -executionpolicy Bypass c:\ pathtoscript.ps1 As you can see, in v.2 Microsoft added an...
  • Accessing Profile Scripts

    Profile scripts are executed automatically when PowerShell starts. The paths to these scripts can be found in $profile: $profile | gm * Host * | % { $_ . Name } | % { $rv = @{}; $rv . Name = $_ $rv . Path = $profile . $_ $rv . Exists = ( Test-Path $profile...
  • Listing Execution Policies

    In PowerShell v.2, there are multiple execution policies. You should use this to view and check the settings: Get-ExecutionPolicy -List ReTweet this Tip!
  • Closing a Program Gracefully

    When you use Stop-Process to kill a program, it will stop instantaneously. The user will get no chance to save unsaved documents: Get-Process Notepad | Stop-Process Try a more graceful way by using an internal .NET method, which then acts as if someone...
  • Stopping a Program Whenever You Feel Like It

    When you launch a program using Start-Process with -passThru, you will get back the process object representing the started program. You can then use this object later to kill the program whenever necessary. $notepad = Start-Process notepad -passthru...
  • Use CHOICE to Prompt for Input

    PowerShell can run native console applications, which can be very helpful. For example, you should take a closer look at CHOICE.EXE, which will prompt you for information: Choice / N / C:123 / M "Enter a number between 1 and 3!" "Your choice...
  • Launching Programs Maximized

    Start-Process has a parameter called -WindowStyle. With it, you can control the window size of the application you launch. You should use this line to launch notepad maximized: Start-Process notepad -WindowStyle Maximized Supported arguments are Maximized...
  • Wait for Programs

    PowerShell launches Windows applications asynchronously. It only waits for the console application so you should use -wait if you want to launch a Windows application and wait for it until it finishes: Start-Process notepad -wait ReTweet this Tip!
  • Open Current Folder in Your Explorer

    If you are stuck in the console and would like to move over to the Explorer GUI, the next line opens your current folder in an Explorer window: explorer . Of course, this only works when the current folder is set to a folder in your file system. ReTweet...
1 2 3 4 5 Next > ... Last »
Copyright 2010 PowerShell.com. All rights reserved.