November 2010 - 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
  • Resetting Network Adapters

    Sometimes, it is necessary to reset network adapters, such as after you changed settings for that adapter in your registry. Resetting a network adapter is done by first disabling and then enabling it again. Here are three functions you can use: function...
  • Disabling Network Adapters

    If you need to systematically disable network adapters, all you need is the name of the adapter (as stated in your control panel or returned by Get-NetworkAdapter, a function featured in another tip). Of course, you will also need Administrator privileges...
  • Enumerating Network Adapters

    Finding your network adapters with WMI isn't always easy because WMI treats a lot of "network-like" adapters like network adapters. To find only those adapters that are also listed in your control panel, you should make sure to filter out...
  • Launching PowerShell Scripts with Admin Privileges

    If you must ensure that a PowerShell script runs with Admin privileges, you can add this to the beginning of your script: $identity = [ Security.Principal.WindowsIdentity ]:: GetCurrent () $principal = new-object Security.Principal.WindowsPrincipal $identity...
  • Test Admin Privileges

    If you want to systematically test whether you currently have Administrator privileges, you can use this function: function Test-Admin { $identity = [ Security.Principal.WindowsIdentity ]:: GetCurrent () $principal = new-object Security.Principal.WindowsPrincipal...
  • Processing Function Parameters As Hash Table

    If you want to get more control over function parameters, you can treat them as hash table. So in your function, you can then check whether a certain parameter was specified by the caller, and then act accordingly: function Do-Something { [CmdletBinding...
  • Determining Function Parameters Supplied by User

    To find out which parameters that a user submitted to a self-defined function, you can use $PSCmdlet like this: function Get-Parameters { [CmdletBinding()] param ( $name , $surname = "Default" , $age , $id ) $PSCmdlet . MyInvocation.BoundParameters...
  • Re-Running Your Profile

    If you made changes to your profile script and want to see the changes that are in effect without having to close and restart PowerShell, you can simply run your profile script dot-sourced: . $profile However, you may receive (harmless) exceptions this...
  • Create (and Edit) your Profile Script

    Profile scripts are automatically executed whenever PowerShell launches. Your profile script is the perfect place to customize your PowerShell environment, change the prompt, colors, and make any changes you would like to keep in all of your sessions...
  • Enter-PSSession - Do's and Dont's

    Enter-PSSession will let you switch your console input to a remote computer—if remoting is enabled on the target computer. Essentially, anything you enter after Enter-PSSession is sent to the remote computer that you specified with -ComputerName...
  • 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 * ....
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.