PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Forum experts available to answer your PowerShell questions

Power Tips

Power Tips

Syndication

  • Finding Default Outlook Profile

    PowerShell can access COM objects like Outlook Application. These two simple lines return the current Outlook profile: $outlookApplication = New-Object -ComObject Outlook.Application $outlookApplication . Application . DefaultProfileName ReTweet this...
  • Dynamic Methods in PowerShell 4

    Beginning with PowerShell 4.0, method names may come from variables. Here's a simple example: $method = ' ToUpper ' ' Hello ' . $method () This can be useful when the method you want to use depends on something a script would need...
  • Dynamic Parameters in PowerShell 4.0

    In PowerShell, you can use variables in place of properties. This sample script defines the four property names that return profile paths, then queries the properties in a loop: $list = ' AllUsersAllHosts ' , ' AllUsersCurrentHost ' ,...
  • Replacing Specific Characters in a Text

    If you just need to replace characters anywhere in a text, you are easy off. This would capitalize every "l" in a text: "Hello World" . Replace ( ' l ' , ' L ' ) Sometimes, however, you may want to replace individual...
  • Weird Text Formatting (and what to do about it)

    Check out this code and try to find the problem: $desc = Get-Process -Id $pid | Select-Object -Property Description "PowerShell process description: $desc" This code gets the PowerShell host process and reads the process description, then outputs...
  • Finding Services in PowerShell

    Get-Service lists all services on a computer, but the information returned is very sparse. You cannot easily see what a service does, whether it is a Microsoft or third-party service, and which executable runs the service. With a little bit of data consolidation...
  • Getting More Than 1000 Active Directory Results

    By default, Active Directory returns only the first 1000 search results when you use an ADSISearcher. This is a security mechanism designed to prevent unspecific LDAP queries from causing domain controller load. If you do need all search results and know...
  • Hiding Parameters from IntelliSense

    Beginning with PowerShell 4.0, a script author can decide to hide function parameters from IntelliSense. This way, less frequently used parameters can be omitted from ISE IntelliSense menus: function Test-Function { param ( $Name , [ Parameter ( DontShow...
  • Finding Active Directory User Accounts Fast

    The more specific your LDAP query is the faster and less resource intense the query is, and the more precise are the results as well. For example, most people use objectClass to limit search results to a specific object class. To find just user accounts...
  • Finding Active Directory Accounts by SID

    If you know the SID and would like to find the corresponding Active Directory account, then LDAP queries won't work well. For them to work, you would have to reformat the SID to match the LDAP formatting rules which is not a trivial task. A much easier...
  • Searching in Different Domains

    When you use the ADSISearcher type accelerator to find Active Directory accounts, it defaults to the current domain you are logged on to. If you need to find an account in a different domain, make sure you define the search root accordingly. This example...
  • Getting Domain from DN

    A "DN" (Distinguished Name) is the path to an Active Directory object and could look similar to this: 'CN=Tobias,OU=Authors,DC=powershell,DC=local' To get just the domain part of a DN, use code like this: $DN = ' CN=Tobias,OU=Authors...
  • Converting Binary SID to String SID

    Active Directory accounts contain the SID in binary form. To convert the byte array into a string representation, use a .NET function like this: # get current user $searcher = [ ADSISearcher ] "(&(objectClass=User)(objectCategory=person)(sAMAccountName...
  • Finding Current Script Folder

    Beginning in PowerShell 3.0, there is a very easy way of determining the folder a script is located in: $PSScriptRoot. This variable always holds the folder path a given script is stored in. This way, it is simple to load additional resources like other...
  • Getting Active Directory Account Information

    In a previous script you have discovered how easy it is to find Active Directory accounts with just some simple PowerShell code. The result is a search result object, not the actual account object. To get more detailed information about an account, use...
« First ... < Previous 26 27 28 29 30 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.