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
  • Encode and Decode Text as Base64

    Here is a simple way to encode text as a Base64 string: #requires -Version 1 $text = ' Hello World! ' [ Convert ] :: ToBase64String ([ System.Text.Encoding ] :: Unicode . GetBytes ( $text ) , ' InsertLineBreaks ' ) The resulting text looks...
  • Managing Windows Firewall

    Beginning in Windows 8 and Server 2012, there is a cmdlet that helps you enable the client firewall for various profiles: Set-NetFirewallProfile -Profile Domain , Public , Private -Enabled True In previous operating systems, you have to resort to netsh...
  • Finding Recursive AD Memberships

    In AD, there is a strange-looking filter: 1.2.840.113556.1.4.1941. It is called "matching rule in chain" and can be used to quickly find nested memberships. All you need is the DN of a member. Then, you can use it like this: #requires -Version...
  • Clearing Recycle Bin

    Before the advent of PowerShell 5.0, to clear the recycler, you would have to manually delete the content of the hidden $Recycle.Bin folder in the root of all drives that have a recycler. Some authors recommended the use of a COM object called Shell.Application...
  • Force User to Change Password

    Use this code snippet to force a user to change his/her password: #requires -Version 1 -Modules ActiveDirectory Set-ADUser -Identity username -ChangePasswordAtNextLogon $true ReTweet this Tip!
  • Get Automated First Level Support Response

    Here is a fun function to provide you with a good first level support response in case everyone is off for Christmas: #requires -Version 3 function Get-FirstLevelSupportResponse { $url = ' http://pages.cs.wisc.edu/~ballard/bofh/bofhserver.pl '...
  • Finding Logged On User

    Here are two strategies for finding the currently logged on user: # User logged on to a physical box Get-WmiObject -Class Win32_ComputerSystem | Select-object -ExpandProperty UserName # Owners of explorer.exe processes (desktop is an Explorer process...
  • Get List of Operating Systems

    If your boss needs a list of operating systems used by computers in your AD, this may be a good start: #requires -Version 1 -Modules ActiveDirectory $max = 100 $os = Get-ADComputer -Filter * -Properties OperatingSystem -ResultPageSize $max | Group-Object...
  • Analyze Operating System by Organizational Unit

    Here is a quick script that scans all OUs in your Active Directory for computer accounts, then groups them per OU by operating system: #requires -Version 2 -Modules ActiveDirectory Get-ADOrganizationalUnit -Filter * | ForEach-Object { $OU = $_ Get-ADComputer...
  • Invoke-Expression is Evil

    It can't be reiterated too often: try and avoid the use of Invoke-Expression (Alias: iex). This cmdlet executes whatever it receives and is prone to SQL-injection like attacks. Take a look at this strange one-liner, and run it in a PowerShell console...
  • Creating Colored Excel Reports

    When you open a CSV file in Excel, you get a very fast data import, but the result is "black and white"; CSV data has no way of colorizing cells. As an alternative, you can wrap your data in HTML, and then feed the HTML to Excel. This produces...
  • Creating Code Snippets for ISE

    PowerShell ISE supports code snippets, and you can easily create your own: #requires -Version 3 $code = @' | Where-Object { $_ } '@ New-IseSnippet -Title Where-Object -Description ' adds Where-Object ' -Text $code -Force This adds a new...
  • Turning ForEach-Object into a Function

    ForEach-Object is a powerful pipeline cmdlet, but foremost it is an anonymous function. ForEach-Object is great to build "prototype functions" yet once you find a particular ForEach-Object statement useful, you might want to turn it into a reusable...
  • How Pipeline Cmdlets Map to ForEach-Object

    There are a number of routine pipeline cmdlets like Where-Object and Select-Object, yet the only essential cmdlet is ForEach-Object. All the other pipeline cmdlets are just predefined implementations. Which is good because it saves code. Yet, to understand...
  • Time for Christmas

    It's time for Christmas again, so here is a PowerShell classic: # inspired by: # http://forums.microsoft.com/TechNet-FR/ShowPost.aspx?PostID=2555221&SiteID=45 $notes = @' 4A4 4A4 2A4 4A4 4A4 2A4 4A4 4C4 4F3 8G3 1A4 4Bb4 4Bb4 4Bb4 8Bb4 4Bb4...
< Previous 1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.