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
  • Recording Audio Text Files

    Did you know that PowerShell can record audio messages? All you need is some text. You can then turn the text into spoken language, convert it to a WAV file and play it back or send it to someone. Here’s how: $Path = " $env:temp\file.wav "...
  • Enter Hibernation Mode

    Maybe you are running lengthy tasks at night. Sometimes you may want to place the machine into hibernation once your script is done. Here’s a function that uses a console application to enter hibernation mode: function Invoke-Hibernate { shutdown...
  • Make PowerShell Speak!

    By adding a new system type called System.Speech, you can make PowerShell speak out loudly: Add-Type -AssemblyName System.Speech $synthesizer = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer $synthesizer . Speak ( ' Hey, I can speak...
  • 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...
« First ... < Previous 59 60 61 62 63 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.