A list of useful and fun commands to remember.
1) Using wmiobject
get-wmiobject -list | where {$_.name -like "win32*"} | more
to get a list of classes that provide great information about your computer. Some uses are…
get-wmiobject -class win32_quickfixengineering
(return a history of all patches installed on your computer)
get-wmiobject -class win32_service | where {$_.name -like 'IISADMIN'}
(return if you are running IIS)
2) Using get-childitem
get-childitem c:\ Measure-Object -Character -Word -Line
Lines
-----
89
get-childitem c:\ -force Measure-Object -Character -Word -Line
Lines
-----
141
force hidden files to be visible.
(get-childItem c:\Eftmcon).Count
counting how many items are in a folder.
3) Using select-string and out-string
select-string -path 001460_20081002_1.dat -pattern "2007[0-9]*"
find all lines from a file matching 2007 followed by zero or more numbers and display what that line would look like.
gc crm3.txt | out-string -stream | foreach {$_ -replace "2007","2008"} > text.txt
This will at least replace all 2007 for 2008 and write it out to a file of your choice. Here I use get-content to read in a file in which I then pipe it to out-string to send it out as one string and do my replace.
4) Playing with Merlin
$agent = new-object -com Agent.Control.2
$agent.Connected = 1
$agent.Characters.Load("Merlin")
$merlin = $agent.Characters.Character("Merlin")
$merlin.Show()
$merlin gm
Display Merlin
$merlin.Play("DoMagic1")
Make him animate a move from the $merlin.AnimationNames list
Sources:
- http://www.simple-talk.com/sql/database-administration/why-this-sql-server-dba-is-learning-powershell/
- http://www.microsoft.com/technet/scriptcenter/resources/pstips/jul07/pstip0727.mspx
- http://community.bartdesmet.net/blogs/bart/archive/2006/12/02/PowerShell-_2D00_-Ask-Merlin_3A00_-a-cool-demo-of-using-COM-objects.aspx
Edited: Removed an extra PS in the Merlin.
Edited (10/14/2008): Added the missing "pipes" and "greater than" sign back in, since they were missing.
2 comments:
Hi !
your Merlin code would appear
to have an extraneous 'PS' ...
Regards
Andy
Oops, thanks for the heads up.
Post a Comment