September 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
  • Use Write-Cmdlets with Care!

    There is a fundamental difference between outputting data using Write-Host and just "leaving info behind":" Function test { Write-Host "Result A" "Result B" } When you run the function, you will get back both results...
  • Opening Event Log GUI

    In a previous tip, you learned how to register event log sources and write your own event log entries. With Show-Eventlog, you can easily open the event log user interface to double-check your code results. If you have created your own event logs as described...
  • Creating New Event Logs

    Logging information to your event log is easy when using Write-Eventlog. You will just need to register your own event source first by using New-Eventlog. This . New-Eventlog can also be used to create your very own event logs. This will cCreatinge a...
  • Running Commands Elevated

    You can launch a separate PS environment and elevate it Iif you are running your script in a restricted environment and want to run a specificparticular command with fully elevated privileges:, you can launch a separate PS environment and elevate it:...
  • Prompting for Secret Passwords via Console

    Whenever you need to enter credentials, you can either use Get-Credential or a low- level PS API function like so: $c = $host . ui.PromptForCredential ( 'Log on' , $null , 'test\user' , 'target' ) $c You should nNote that the low...
  • Prompting for Secret Passwords via Console with Powershell

    You can use Read-Host to hide user inputs for safe password prompts: $pwd = Read-Host -AsSecureString 'Enter Password' Enter Password: ****** $pwd System.Security.SecureString However, the result in this case is an encrypted secure string. To...
  • Prompting for Passwords

    If you need to prompt for a secret password and do not want it to be visible while entered, you should use Get-Credential. This cmdlet returns a credential object, which contains the entered password in encrypted format. You should then call GetNetworkCredential...
  • Finding Static Methods

    You will find that types can contain very useful methods. To get a list, you can pass the type to Get-Member, but do not forget to specify the -Static switch. Without it, you won't see the static members, but instead just the (rather useless) instance...
  • Identifying 64-Bit-Environments

    You will find that one great advantage of 64bit-Environments is the address width of 8 bytes instead of 4 bytes. You can use this to identify whether a script runs in a 32-bit or 64-bit environment. You should simply take a look at pointers and their...
  • Finding Maximum Values

    Numeric types can store numbers in certain ranges. A byte for example stores values in the range 0-255. But do you know just what the range is for an Int32 or Int64? You can very simply ask PowerShell: [ Int32 ]:: MaxValue 2147483647 [ Int64 ]:: MaxValue...
  • Finding Days in Month

    If you need to determine the days in a given month, you can use the static DaysInMonth() function provided by the DateTime type. As you can see, the days in a month are not always the same for every year: [ DateTime ]:: DaysInMonth (2009, 2) 28 [ DateTime...
  • Finding Leap Years

    You will find that the DateTime type supports a number of static methods to check dates. For example, you can check whether a year is a leap year like this: [ DateTime ]:: IsLeapYear (1904) ReTweet this Tip!
  • Getting Short Dates

    Objects contain useful methods to access the object data. For example, DateTime objects support methods to display the date and time in various formats. Use this if you just need a short date: ( Get-Date ). toShortDateString () Use this to see all methods...
  • Getting Alphabetical Listings

    Unfortunately, PowerShells special ".." operator only supports numeric ranges: 1..10 You can use type conversion to get a range of letters: $OFS = "," [ string ][ char []](65..90) This will then create a comma-separated list of letters...
  • Counting Special Characters

    Type conversion can help you count special characters in a text. For example, if you'd like to find out the number of tab characters in a text, you should do this: @([ Byte []][ char []] $text -eq 9). Count This line will convert the characters in...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.