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
  • Create Group Policy Reports

    Windows Server 2008 R2 comes with the GroupPolicy PowerShell module. You might have to install that feature first before you can use it – run these lines with full Administrator privileges: Import-Module ServerManager Add-WindowsFeature GPMC Once...
  • Admin Privileges Enabled?

    If you want to know whether your script has currently full Administrator privileges, here is an (admittedly long) one-liner that tells you: ( New-Object System.Security.Principal.WindowsPrincipal ([ System.Security.Principal.WindowsIdentity ] :: GetCurrent...
  • Locking Workstation

    If you ever feel the need to lock your interactive session via PowerShell, here’s a function that can do this (and also illustrates how to use low-level API functionality): function Lock-WorkStation { $signature = @" [DllImport("user32...
  • Logging Off

    Stop-Computer and Restart-Computer can shutdown and restart a machine, but there are things they cannot do, for example logging off the current user. Here’s a simple function wrapper that utilizes a standard console application and wraps it into...
  • Check for 64-bit Environment

    In PowerShell v3 (CTP2 publicly available) it is finally a snap to determine whether you are on a 64-bit machine and/or shell. PowerShell 3.0 is able to provide this useful information thanks to .NET Framework 4.0 BTW PS > [ system.environment ] :...
  • Stripping Decimals Without Rounding

    When you divide numbers and just want the decimals before the decimal point, you could cast the result to integer. However, this would also round the result: PS > 18 / 5 3 . 6 PS > [ Int ]( 18 / 5 ) 4 To strip off all decimals behind the decimal...
  • The Two Faces of -match

    The -match operator can be extremely useful because it accepts regular expression patterns and extracts the information that matches the pattern: PS > ' PC678 had a problem ' -match ' PC(\d{3}) ' True PS > $matches Name Value --...
  • Finding Email of Logged On User

    In an Active Directory environment, PowerShell can easily find the currently logged on user and retrieve AD information about that user, for example, his or her email address: $searcher = [ adsisearcher ] "(samaccountname=$env:username)" $searcher...
  • Remotely Launching Processes

    Unfortunately, the Start-Process cmdlet has no -ComputerName parameter so you cannot use it to launch processes on remote machines. Use WMI instead! This line will run calc.exe on your local machine: PS > ( Invoke-WmiMethod Win32_Process Create calc...
  • Keeping Remote Programs Running

    When you use PowerShell Remoting (like the Enter-PSSession cmdlet) to connect to another machine and then start a program using Start-Process, the program is automatically associated to your remote session. Once you leave and discard your remote session...
  • Converting TABs to Spaces

    When you want to publish PowerShell code, you may want to make sure that all TAB characters are converted to one or more spaces to save space. Here's the code that turns TAB characters to spaces: PS > $text = "This is a`tTAB-delimited`tText"...
  • Removing Multiple White Spaces

    Removing multiple white spaces from text is easy in PowerShell. Simply use -replace operator and look for whitespaces ("\s") that occur one or more time ("+"), then replace them all with just one whitespace: PS > ' [ Man, it...
  • Removing Options from Command String (Enhancement)

    In a previous tip we showed how you can remove options from a command line text using -replace. Here is a more versatile approach. It will remove any character or word that starts with "/" and then remove all trailing spaces as well: PS >...
  • Remove Options from Command String

    Let's assume you'd like to remove all options from a raw text command such as this one: xcopy "C:\Some Folder" "C:\Some New Folder Name" /y /r /Q Since all options start with "/" and are a single character, you can...
  • Using Shared Variables

    By default, all variables created in functions are local, so they only exist within that function and all functions that are called from within this function. Sometimes, you'd like to examine variables defined in a function after that function executed...
« First ... < Previous 72 73 74 75 76 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.