May 2009 - 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
  • Calling PowerShell from VBScript

    Maybe you are happy with other scripting languages, like VBScript, and would like to stick to that for awhile. Still, you'd like to enhance your scripts with PowerShell functionality. To call a PowerShell script from another scripting language like...
  • Launching Files with Arguments

    Often, you want to submit additional arguments to a program file when you launch it, such as you want to open IE and have it navigate to some Web site. One way is to navigate to the folder that the program file resides in, and then call the file with...
  • Launching Files with Spaces

    What if you'd like to launch a file with spaces in its path? The first rule is that spaces are separators, so PowerShell would separate it at the spaces and break it up in several invalid paths, which is no good. So whenever a path contains spaces...
  • Launching Files without Specifying a Path

    For security reasons, PowerShell launches files only when specified with a relative or absolute path name. The only exceptions to this rule are files located in folders listed in the %PATH% environment variable. To add a new folder path to your %PATH...
  • Launching Files

    The most important rule: always specify either an absolute or relative file path to whatever you want to launch - except if the file is located in a folder listed in the PATH environment variable: $env:path So, to launch the calculator, all you do is...
  • Getting Real Paths

    PowerShell uses virtual drives, which sometimes have a close mapping to the "real" drives you see in Windows Explorer. However, sometimes these drives have no apparent real-world relation. Let's say you have created the following drive "test"...
  • Deleting Things

    To delete things in the file system, you normally use a command like "del", which is an alias and points to Remove-Item in PowerShell: get-command del You can use del to delete a variety of things: Delete a variable named "test": del...
  • Append Information to Text Files

    Add-Content is a versatile command if you need to add additional content to text files. For example, you can create log file entries like this: Add-Content $home \ logfile.txt ( "{0:dd MM yyyy HH:mm:ss} New Entry" ` -f ( Get-Date )) & "...
  • Secret -Force Switch

    PowerShell automatically displays all object properties when you output the object to the console. Here is an example: Get-WmiObject win32_bios Actually, PowerShell uses its internal type system to select which object properties to show. This is smart...
  • Returning Exit Code from Script

    When running a PowerShell script, you may want to return a numeric exit code to the caller to indicate failure or success. You should use the "exit" statement to return whatever numeric exit code you want. The following line in a script would...
  • List Local Groups

    If you'd like to get a list of all local Groups on your computer, you can use this line: Get-WMIObject Win32_Group - filter "domain='$env:computername'" | select name,SID This uses WMI to retrieve all Groups where the domain part...
  • List All Group Memberships of Current User

    In case you need to get a list of all of your current Group memberships as derived from your current access token, use this line: ([ System.Security.Principal.WindowsIdentity ]:: GetCurrent ()). Groups | Foreach-Object { $_ . Translate ([ System.Security...
  • Working Remotely With WMI

    PowerShell v1 has no support for working remotely but WMI natively is able to work on local or remote machines. Simply use the -computername parameter to access remote systems. You can provide an IP address, a NetBIOS name and even a comma-separated list...
  • Deleting Shares

    If you'd like to get rid of a file share, such as the one you created via WMI in our last tip, this is how you can do it: ( Get-WMIObject Win32_Share - filter "Name='$sharename'" ). Delete () As with share creation, you need admin...
  • Creating New Shares

    You can use WMI to help create new file shares. This is the line you need: md c:\testfolder ([ wmiclass ] 'Win32_Share' ). Create ( 'C:\testfolder' , ` 'myShare' , 0, 5, 'A new share' ). ReturnValue This will create a share...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.