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
  • Forwarding Selected Parameters

    In a previous tip you learned how you can forward function parameters to cmdlets. But what if you just want to forward some of the parameters? Here is a sample: function Get - BIOS ( $ComputerName , $Credential , [ switch ] $Verbose ) { $a = $global:psboundparameters...
  • Clean your TEMP folder!

    When disk space gets low, you may want to clean up your temporary folder. The code deletes all files that are older than 30 days to make sure you're not dumping anything that's still needed: $cutoff = ( Get-Date ) - ( New-TimeSpan -Days 30 ) ...
  • Filtering Files or Folders

    To filter folder content by file or folder, check whether the Length property is present. It is present for files and missing in folders: Dir $env:windir | Where-Object { $_ . Length -eq $null } Dir $env:windir | Where-Object { $_ . Length -ne $null ...
  • Office365 Cmdlets

    Office365 comes with a complete set of PowerShell cmdlets. To review the cmdlets and what you can do with them, visit this URL: http://onlinehelp.microsoft.com/en-us/office365-enterprises/hh125002.aspx ReTweet this Tip!
  • Forwarding Parameters

    To forward function parameters to a cmdlet, use $psboundparameters automatic variable and splatting. Here is a sample: function Get - BIOS ( $ComputerName , $Credential ) { Get-WmiObject Win32_BIOS @ psboundparameters } Your function Get-BIOS works both...
  • How Long Has Shell Been Running?

    To find out how long your PowerShell session has been running, try this code snippet: (((( Get-Date ) - ( Get-Process -id $pid ) . starttime ) -as [ string ]) -split ' \. ' )[ 0 ] ReTweet this Tip!
  • Enabling Remote WMI and DCOM

    Many cmdlets have a built-in -ComputerName parameter that will allow for remote access without using the new PowerShell remoting. For this to work, your firewall will need to be adjusted on the target machine: In addition, some cmdlets (like Get-Service...
  • Creating Local Admins (Part 2)

    In a previous tip, we showed you how to create a new local admin account using ADSI. On Windows 7 and Server 2008, it is much easier to use net.exe instead: net user AdminAccount1 /ADD net localgroup Administrators AdminAccount1 /ADD ReTweet this Tip...
  • Creating Local Admins

    Here is a piece of code that will create a local user account and put it into the local Administrators group: $computername = $env:computername # place computername here for remote access $username = ' AdminAccount1 ' $password = ' topSecret...
  • Adding Members to Local Group

    To manage local groups, you can think about using net.exe. It may be much easier than using COM interfaces. The next line will add a local user account to the local Administrators group: net localgroup Administrators Tobias /ADD This functionality may...
  • Bulk Renaming Files

    Rename-Item can rename hundreds of files in one step. Have a look: $global:i = 1 ; dir c:\test1\ -Filter cover * . jpg | Rename-Item -NewName { "picture_$i.jpg" ; $global:i ++ } This line will take all *.jpg files in c:\test1 and rename them...
  • Monitoring Folder Content

    You can use a FileSystemWatcher object to monitor a folder and write a log for all newly created files. For example, this can be used as an "Inbox" for incoming job requests. $log = " $env:temp\newfiles.txt " $folder = $home $timeout...
  • Renaming Computers

    PowerShell can also rename computers. The next example will read the serial number from the system enclosure class and rename the computer accordingly (provided you have local admin privileges): $serial = Get-WmiObject Win32_SystemEnclosure | Select-Object...
  • Returning Array in One Chunk

    In a previous tip, we showed you how adding a single comma can change the way functions return arrays. With this trick, you can force a PowerShell function to return an array in one chunk. Have a look: function test { ( 1 . .10 ) } Test | ForEach-Object...
  • Return Arrays

    Normally, PowerShell will not preserve the type of an array returned by a function. It is always reduced to Object[]: function test { $al = [ System.Collections.ArrayList ]( 1 . .10 ) $al } ( Test ) . GetType () . FullName By adding a comma (telling PowerShell...
« First ... < Previous 59 60 61 62 63 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.