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
  • Adding Extra Information

    Sometimes you may want to tag results returned by a cmdlet with some extra information, such as a reference to some PC name or a timestamp. You can use Add-Member to tag a note property to the result. This line gets all services and adds two new columns...
  • Making Objects Read/Write

    Whenever you pipe objects through Select-Object, you actually get a copy of the original object. All properties are now readable and writeable, so you can change the object properties in any way you like. This example reads memory information and then...
  • Creating Relative Dates

    To create relative dates like "10 days ago," there are two paths. Administrators often add or remove time spans created by New-Timespan: ( Get-Date ) - ( New-TimeSpan -days 10) Developers prefer object methods: ( Get-Date ). AddDays ( - 10)...
  • Create Remoting Solutions

    Whenever you use WMI (Get-WMIObject) to retrieve information, it's a snap to turn a local solution into a remotable solution. You can just add the parameter -Computername to Get-WMIObject. In a previous tip, you learned how to examine physical memory...
  • How Much RAM Do You Have?

    Ever wondered what type of RAM your PC uses and if there is a bank available to add more? Ask WMI! This example also converts the cryptic type codes into clear-text using hashtables to create new columns: $memorytype = "Unknown" , "Other"...
  • Accessing Object Properties

    Objects store information in various properties. There are two approaches if you would like to get to the content of a given property. One is commonly used among developers, the other one among admins. Both will get you the same result. Have a look: #...
  • Changing File/Folder Creation Date

    You should use this approach if you need to change the creation time of a folder or file after you have created it: Get-Childitem c:\testfolder | Foreach-Object { $_ . CreationTime = '1/1/1972 10:35' } It will change creation time of c:\testfolder...
  • Changing Error Background Color

    If you would like to make error messages more readable, you can change their background color from black to white: $host . PrivateData.ErrorBackgroundColor = 'White' Use this line to see the colors that you can assign: [ System.Enum ]:: GetNames...
  • Removing Empty Things

    How do you exclude objects based on empty properties? For example, WMI returns all kinds of "network adapters:" Get-WMIObject Win32_NetworkAdapterConfiguration To focus only on those that have an IPAddress assigned, you should exclude any object...
  • Filtering Day of Week

    You can also use this little helper function if you run scripts every day and want to make sure they don't do anything on weekends: function is-Weekend { ( Get-Date ). DayOfWeek -gt 5 } You can use it like this: If ( is-Weekend ) { 'no service...
  • Finding Object Types

    When you pipe the result of a command to Get-Member, it examines the returned objects and shows the properties and methods. Use this line if you would like to focus on the different object types a command returns: Dir $env:windir | Get-Member | Group...
  • Built-in Methods

    Strings contain all the methods you may need to access its content or manipulate it otherwise. Here is how you can list those methods: "Hello" | Get-Member -memberType * method For example, to trim all leading and trailing white space from a...
  • Stopping Programs Gracefully

    While Stop-Process will stop a process immediately in PowerShell, it will also destroy all data that hasn't yet been saved. You can try a more graceful approach that would give the user a warning and allow them to save data: $proc = Get-Process notepad...
  • Create HTML System Reports

    ConvertTo-HTML is a great way of creating system reports because you can combine information gathered from different sources into one report. The following code will create a report with service information that is gathered from Get-Service, operating...
  • Create HTML reports

    ConvertTo-HTML will convert text information into simple HTML, which can then be saved to disk. These reports will work fine, even though they are pretty ugly. Using just a simple HTML style sheet, your HTML reports will look a lot better: $style = @...
« First ... < Previous 72 73 74 75 76 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.