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
  • Catching Errors in Native EXEs (Part 2)

    All versions Here is yet another approach that you can use to detect errors emitted by console applications: $ErrorActionPreference = ' Continue ' $result = net.exe user UserDoesNotExist 2 >& 1 # $? is $false when something went wrong if...
  • Replacing NTFS Permissions with SDDL Information

    All PowerShell versions With Get-Acl, you can output the security information from files and folders as plain text in SDDL format (Security Descriptor Definition Language): $FolderToRead = ' C:\folder1 ' $securityDescriptor = Get-Acl -Path $FolderToRead...
  • Cloning NTFS Permissions

    All PowerShell Versions Here is some simple code that reads the NTFS permissions from one folder and applies the exact same settings to another. Note that both folders must exist: $FolderToCopyFrom = ' C:\folder1 ' $FolderToCopyTo = ' C:\folder2...
  • Catching Errors in Native EXEs (Part 1)

    All Versions When you run native console EXE commands such as robocopy.exe, ipconfig.exe, or similar commands, you can handle errors raised by these commands: try { $current = $ErrorActionPreference $ErrorActionPreference = ' Stop ' # this will...
  • Using WMI Inheritance

    All Versions WMI classes are inherited from each other, and that’s something you can take advantage of. Take this line: PS> Get-WmiObject -Class Win32_Printer It will return all printers found by WMI. Printers are inherited from more generic...
  • Getting System Uptime

    All Versions This simple function will return the current system uptime: function Get-Uptime { $millisec = [ Environment ] :: TickCount [ Timespan ] :: FromMilliseconds ( $millisec ) } ReTweet this Tip!
  • Finding Process Owners

    All PowerShell versions To find out who owns a particular process and how many instances are running, try this simple piece of code: $ProcessName = ' explorer.exe ' ( Get-WmiObject -Query "select * from Win32_Process where name='$ProcessName'"...
  • Parsing DISM Log File

    PowerShell 2.0 and later In your Windows folder, you find all kinds of system log files. One is DISM.log which contains information about the configuration of Windows (feature state and more). Here is a simple approach illustrating how you could parse...
  • Setting Active Directory Attributes

    ActiveDirectory Module To set AD attributes for a user account, PowerShell uses hash tables. That’s a versatile approach that lets you specify any attribute name and associate it with any value. This simple example would set the attributes “l”...
  • Bulk Creating AD Users from Excel Sheets

    Module ActiveDirectory To create a large number of new Active Directory users, you can import the user data from a CSV file, for example export an Excel sheet to CSV. Next, this piece of code will turn the CSV data into real Active Directory user accounts...
  • Removing AD Group Members

    Module ActiveDirectory To remove one or many users from an Active Directory group, try this approach: $user = @ () $user += Get-ADUser -Filter { Name -like ' H* ' } $user += Get-ADUser -Filter { Name -like ' *ll* ' } $user . Name Remove...
  • Steps to Configure PowerShell (Part 3)

    All PowerShell versions If you use PowerShell at home or in an environment without central group policy management, here are some additional steps you should consider to make PowerShell fully functional. To use the PowerShell remoting feature against...
  • Steps to Configure PowerShell (Part 1)

    PowerShell 2.0 and later If you use PowerShell at home or in an unmanaged environment, here are some steps you should consider to make PowerShell fully functional. To check out the PowerShell version you use, try this: PS> $PSVersionTable.PSVersion...
  • NULL Values in Arrays

    All PowerShell versions Whenever you assign NULL values to array elements, they will count as array elements, but will not be output (after all, they are NULL aka nothing). This can lead to tough debugging situations, so when the size of an array does...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.