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
  • Get WebClient with Proxy Authentication

    If your company is using an Internet proxy, and you'd like to access Internet with a webclient object, make sure it uses the proxy and supplies your default credentials to it. You could write a little helper function to get such a pre-configured webclient...
  • Strongly Typed Arrays

    When you assign strongly typed values to an array, the type declaration will remain intact only as long as you do not add new array content: $array = [ Int []](1,2,3,4,5) $array . GetType (). FullName System.Int32 [] $array += 6 $array . GetType (). FullName...
  • Create Files and Folders in One Step

    Use New-Item like this when you want to create a file plus all the folders necessary to host the file: new-item -type file -force c:\subfolder\anothersubfolder\yetanotherone\ test1.txt This will create the necessary folders first and then insert a blank...
  • Running 32-Bit-Code on 64-Bit Machines

    Some code may not work right on 64-Bit machines. Use this approach to make PowerShell execute code in an isolated 32-Bit PowerShell session and hand over its results to your 64-Bit PowerShell: $32bitcode = { [ IntPtr ]:: Size } # run on 64bit machine...
  • Get Notification When a Background Job is Done

    When you assign long-running commands to a background session, you may want to get some notification when the job is completed so you don't have to constantly check its status. Here is how: $job = Start-Job -Name GetLogFiles { dir $env:windir * ....
  • Running Commands in the Background

    You can also transfer commands into another PowerShell session and run it in the background. This will find all log files recursively in your Windows folder and all of its sub-folders as background job: $job = Start-Job { Dir $env:windir * . log -recurse...
  • Escaping Spaces

    You should remember that spaces are special characters in PowerShell, too. They are token delimiters, and once you feed arguments to a native command, PowerShell will separate arguments by space and feed the individual arguments one by one to the native...
  • Why Native Commands Fail In PowerShell

    You probably already know that not all native commands work equally well in PowerShell. Have a look here: find / I / N "dir" * . ps1 In cmd.exe, this line finds all occurrences of "dir" in all PowerShell scripts that are located in...
  • Downloading Internet Files with Dialog

    There is a great way to download large files from the Internet. This example downloads a tutorial video from Idera that, once downloaded will run in your media player: [ reflection.assembly ]:: LoadWithPartialName ( "Microsoft.VisualBasic" ...
  • Using OpenFile Dialog

    You can use this code to open a standard OpenFile dialog in your PowerShell scripts: [ System.Reflection.Assembly ]:: LoadWithPartialName ( "System.windows.forms" ) | Out-Null $dialog = New-Object System.Windows.Forms.OpenFileDialog $dialog...
  • Finding Methods with Specific Keywords

    As such, .NET Framework is huge and full of stars, and it is not easy to discover interesting methods buried inside of it. You can use the next lines to find all methods with a given keyword: $key = 'Kill' [ System.Diagnostics.Process ]. Assembly...
  • Running Programs as Different User

    If you ever needed to run a program as someone else, you can use Start-Process and supply alternate credentials. When you do that, you should also make sure you specify -LoadUserProfile to load the user profile unless you do not need it: Start-Process...
  • Run Programs Elevated

    If you have User Account Control (UAC) enabled, you may want to run a program elevated. That's easy using Start-Process and the -verb parameter. The next line launches an elevated PowerShell console: Start-Process powershell -verb runas ReTweet this...
  • Launching Programs and Keeping in Touch

    Normally, when you launch a program from inside PowerShell, you will lose contact to it. However, by using Start-Process with the -passthru parameter, you will return the process object, which you can then store and later use to check the execution status...
  • Translating Culture IDs to Country Names

    Have you ever wondered what a specific culture ID means? Here is a nifty function that will translate a culture ID to the full culture name: [ System.Globalization.CultureInfo ]:: GetCultureInfoByIetfLanguageTag ( 'ar-IQ' ) ReTweet this Tip!
« First ... < Previous 72 73 74 75 76 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.