I will present a seminar at ITWorx CuttingEdge club about PowerShell.
The seminar's presentation :
I will present a seminar at ITWorx CuttingEdge club about PowerShell.
The seminar's presentation :
Using 2 lines of PowerShell to get the Physical memory of a remote computer :
$mem = Get-WmiObject win32_computersystem -computername server-vm-0001
$mem.totalphysicalmemory / 1Gb
This is just an example, and other system information can be retrieved through using the WMI objects, the above script can be easily extended to get the Physical memory (or anything) for all the machines in a whole network.
It seems that robots is no longer a luxury gadget, starting from robo-bugs that one can build from capacitors and resistors found on any old electronic device or radio, to DIY robots and ready to rock robots, the span is very wide.
I found this video from IEEE robotics blogger Mikell Taylor very helpful, she reviews the latest robot kits available in the market.
A friend of mine was organizing a public event, the event has a website and they were asking for registration through a registration webpage or filling a word document and send it by email.
My friend got hundreds of documents on his email, and hence came the problem of processing those documents.
Let us see how we can automate processing those documents using PowerShell.
Firstly, we need to de-attach all the documents from the emails, and save them into a folder. Although this is an interesting thing to accomplish using PowerShell, but my friend had this already done for me using Attachment Extractor <Okay … he was using ThunderBird and this post is not intended for arguing that I will prefer Outlook>
Now, we have all the documents in one folder; or many folders. (We can simply gather them from the whole drive using only 2 lines of PowerShell)
Secondly, let us process all those documents and get all the data out of them into a CSV file ready for Excel, or importing into a database.
1. Getting the folder path and open Word in Hidden mode
$docPath = $args[0]
$all_docs = Get-ChildItem $docPath -filter "*.docx"
$word = New-Object -comobject "Word.Application"
$word.Visible = $False
We are getting the documents folder as a parameter for our script, then we will get all the documents by calling Get-ChildItem and filter that to files with .docx extension, then we created an instance from Word and setting its Visibility to false so we are now working silently.
2. Open each document and list the ContentControls
foreach ( $doc in $all_docs)
{
Write-Host "Processing :" $doc.FullName
$doc = $word.Documents.Open($doc.FullName);
$controls = $doc.ContentControls.Count
Here we are using the foreach cmdlet to enumerate the documents we found in the folder, and then open each of them in Word using the Open method in the Documents collection.
My friend used the Content Controls to restrict users to edit certain fields in the document so he can process the document latter, and this is better than a plain word document to pull your hair trying to develop a parser for it.
Word object model provides a ContentControls collection, which will be holding all the content controls and their properties.
We put a reference to all the content controls in a variable so we can use it afterwards.
3. Create a collection of custom objects holding our data
$item = New-Object System.Object
foreach ( $control in $doc.ContentControls )
{
$item | Add-Member -type NoteProperty -name $control.Title -value $control.Range.Text
}
$all_items += $item
Here we are using the New-Object cmdlet to create a custom object, and using the Add-Member cmdlet to create properties on the fly.
Each property name is the ContentControl’s Title, and the property value equals to the text inside this control. After that we add the new object to a collection
4. Save the collection to a CSV file
$all_items | Export-CSV "Data.CSV"
The PowerShell guys had done a great job here, if we just pipe our collection to the Export-CSV cmdlet, we now has a reflection based enumeration of our objects dumped to the CSV file with an automatic header.
Finally, you got served my friend.
The whole script and sample document can be downloaded here:
To run the script, call it and pass the folder path:
>> ./Process-Documents.ps1 "path-to-the-documents"
I (and I think all of us) have documents scattered every where in data drive.
Today I wanted to get all the word documents on my D: drive and put them on a shared folder for archiving.
Since I was playing with PowerShell recently, I thought it will be nice to write a script that do that, and the following is what I have written:
| $files = Get-ChildItem -recurse -filter "*.doc*" |
I saved those 2 lines into a file [backup-docs.ps1] and opened PowerShell and navigate to my drive and called this script,and in seconds I found all my documents in the E:\Docs folder ; Thanks to PowerShell
Paul Stovell (MVP from Australia) had a nice post on his blog; it seems like a fictional dialogue between 2 developers one of them is a new member ask questions to his elder colleague, this dialogue whill light the pulp on how some decisions we take during development, will lead to confusions and hard times to maintain the source code.
Enjoy: http://www.paulstovell.com/blog/the-inline-sql-application-six-months-later
I think this post's title is a little bit cryptic, but if you did understood my intentions; you are possibly an IoC geek and may be you know what I am trying to say here.
So, let me explain the phrase from right to left:
Unity: The Unity Application Block (Unity) is a lightweight, extensible dependency injection container with support for constructor, property, and method call injection; it will be part of Entrprise Library version 4.0 and it has its own space on codeplex (www.codeplex.com/unity )
MVC : The famous Model-View-Controller design pattern used in the presentation layer since its invention in the 70s.
Wiring: The MVC pattern requires 3 classes to exist and coordinate together, the Controller class will need an instance of the Model and View, and the View will need a reference to the Model so it can handle the display of the Model.
In the normal life of any MVC based application, we will need some code like this:
Model m = new Model();
View v = new View();
Controller c = new Controller ( m , v);
c.Start();
By this; I mean wiring the classes together so they will be able to communicate.
Auto-Wiring: Is the mechanism of automatically wiring the classes together without the need to write the above code again and again.
One of the auto-wiring techniques is to use the Dependency Injection pattern, and instead of building my own implementation of it, I am using the Unit Application Block.
Unity is able to discover the dependency of the classes based on their constructors, so in the above example; Unity will discover that Controller will need a Model and a View instance so the Controller can be instantiated, and also the same for the View.
Using Unity, all what is needed is to call the Resolve method in the UnityContainer and it will instantiate all the dependencies for us (namely the Model and the View), and will instantiate the controller and pass it the created instances auto-magically.
UnityContainer container = new UnityContainer();
Controller c = container.Resolve<Controller>();
c.Start();
I have made a sample application, you can check to see the above code into action. You will need VS2008,no need to download or setup Unity, since its assemblies are included.
Agree, Disagree? I like to hear your comments.
Today I run out of space on my C: drive, so I used the Desk Clean up wizard to free some desk space for me, it asked me to clean many things and I blindly checked them all.
Then when I tried to Hibernate the computer, I didn't find the Hibernate option.
Thanks Google, I found a Microsoft KB Article (The Hibernate option is not available in Windows Vista http://support.microsoft.com/kb/929658)
The article says "This issue occurs if one of the following conditions is true: 1) The Disk Cleanup Utility and has been used to delete the Hibernation File Cleaner. " and there are some other conditions ... but what I did to clean my disk space prevented me from Hibernation !!!!
Hmmm, Is it my fault any way ... I shouldn't check all the items in the wizard :(
Oh, I forgot to tell you how to get Hibernate again ... on the command prompt type:
| powercfg -H ON |
Spring.NET Expression Library
http://www.springframework.net/doc-latest/reference/html/expressions.html
Flee
other ?
Sometimes you feel that the geek inside you is about to explode , this happened to me when I went to buy a new toy to my daughter from the toy store and seen the RC Cars.
I found cheap remote controlled cars for less than 100 LE ( < 15$ )
The toy cars are remotely controlled using Radio frequency, they are called RC Cars for (Radio Controlled Cars)
Once I seen the remote control, I though immediately if it is possible to connect that remote to my PC and control the car using my keyboard !!! why do that ... I don't know but read the article from the beginning again and you will understand.
So, I did a quick search and I found other geeks thinking in the same line, this post (http://www.hackaday.com/2005/02/01/control-an-r-c-car-from-your-pc/) is what I was looking for and this (http://www.engr.uvic.ca/~sbowman/more-moreBetterCircuitDiagram.gif) is the circuit used to connect the remote to the computer parallel port.
As soon as I do that , will let you all know :)
lots of interesting articles about XML, XPath , XSLT for .net developers:
http://msdn2.microsoft.com/en-us/library/cc294436.aspx
Check them out
MSDN Robotics Forums
http://forums.microsoft.com/MSDN/default.aspx?ForumGroupID=383&SiteID=1
Microsoft Robotics Downloads
http://msdn2.microsoft.com/en-us/robotics/aa731520.aspx
Introductory Courseware for Microsoft Robotics Studio
Robots and BizTalk Services
http://channel9.msdn.com/ShowPost.aspx?PostID=386824
Microsoft Robotics Studio and Lego Mindstorms NXT
http://channel9.msdn.com/ShowPost.aspx?PostID=325661
Microsoft Robotics Tour:
Part 1:CCR, VPL, Simulation - http://channel9.msdn.com/Showpost.aspx?postid=303072
Part 2:CCR, VPL, Simulation - http://channel9.msdn.com/Showpost.aspx?postid=303135
Singapore Sumo-Robot How-To
#1: Getting the Robotics Bits
http://channel9.msdn.com/Showpost.aspx?postid=309026
#2: Understanding Your Robot's Inputs and Outputs
http://channel9.msdn.com/Showpost.aspx?postid=309686
#3: Building Your First Robot
http://channel9.msdn.com/Showpost.aspx?postid=309685
#4: Understanding Your Robot's Code Methods
http://channel9.msdn.com/Showpost.aspx?postid=309688
CCR Programming - Jeffrey Richter and George Chrysanthakopoulos
http://channel9.msdn.com/showpost.aspx?postid=219308
Microsoft Robotics Studio
http://channel9.msdn.com/ShowPost.aspx?PostID=206574
Walter Stiers - Academic Relations Team (BeLux)
http://blogs.msdn.com/walterst/archive/tags/Robotics/default.aspx
Windows Embedded Academic Program (WEMAP)
The Windows Embedded Academic Program (WEMAP) helps provide a better understanding of the Windows CE and Windows XP Embedded operating systems to academia. As a participant in this program, you can learn how to educate the next generation of embedded developers on Windows Embedded technologies. You can participate in a variety of programs, including student competitions like the Windows Embedded Student ChallengE and discounted hardware programs, such as the Hardware Empowerment Program.
HowTo Videos: Robotics and .Net fundamentals
http://blogs.msdn.com/dawate/archive/2007/12/14/robotics-and-net-fundamentals-series.aspx
http://channel8.msdn.com/Posts/HowTo-Videos-Robotics-and-Net-fundamentals/
To exit an Windows Forms Application, we have the option to use Application.Exit() or the System.Environment.Exit().
The difference is discussed here (http://geekswithblogs.net/mtreadwell/archive/2004/06/06/6123.aspx) and the suggestion was made to use System.Environment.Exit() for console applications since it can accept an exit code which will be returned to the Operating System.
But for Windows applications, what should we do ?
I have tried to modify the Main function definition so it will have a return value, a lesson learned from C/C++ old days, then add a property to my main form to indicate if my application would report a success or failure report
And so, my Main function will look like this :
This approach can be extended to report different exit codes for different scenarios (think about MSBuild or NAnt exit codes).
Jeffrey Palermo has an interesting article on MSDN about TDD in .net development, discussing the process of Red-Green-Refactor, benefits of TDD and what characterizes a good unit test
According to Microsoft definition; the Sync Framework is "a comprehensive synchronization platform enabling collaboration and offline for applications, services and devices with support for any data type, any data store, any transfer protocol, and network topology."
What does it mean for us developers?
Hmmm, I am trying to think about an example here. Take Microsoft Outlook and Microsoft Groove as an example; both are collaboration platforms, can work offline and online, and support many protocols.
Look at the technical options that we have now if we need to build something like this:
I don't know of any other option, but each of the above options has different approach and has issues and limitations as well.
The Sync framework is coming to put a uniform way of building applications like Outlook without pain, the framework is now addressing Data, files and feeds synchronization in addition to having the ability to role your own providers; think about synchronizing an Oracle database with an Outlook folder or a SharePoint list.
The concept is discussed in Introduction to the Microsoft Sync Framework Runtime , while the motivations, goals and approach is briefly discussed by Moe Khosravy the Lead Program Manager on his article Next Generation Synchronization Framework or watch him talk about it on Channel8 http://channel8.msdn.com/Posts/Sync-your-Facebook-with-your-phone-Whats-the-Sync-Framework/
There is also a number of Screen casts http://blogs.msdn.com/sync/archive/2008/01/14/microsoft-sync-framework-sync-services-for-ado-net-video-webcasts.aspx
So, what are you waiting for, go ahead and download the SDK (http://www.microsoft.com/downloads/details.aspx?FamilyId=C88BA2D1-CEF3-4149-B301-9B056E7FB1E6&displaylang=en) and start playing.
Interested on the subject, or have played with it … let me know by commenting on this post
I used the DateTimeFormatInfo class to get the month name as a string by calling this method GetMonthName(int) , then I found that it retrun the English representation of the month even in non english regional settings (Windows locale).
The culture aware class is the CultureInfo, which can be accessed from the Current thread, so simply call:
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.GetMonthName(monthNumber);
to get a culture specific month name.
ARCast.TV - Exotic Locations, Global Perspective and Architectural Insight… It’s ARCast.TV with Ron Jacobs
RSS Feed :http://channel9.msdn.com/rss.aspx?ShowID=26
Scott Hanselman - Scott Hanselman's Thoughts on .NET, WebServices, and Life , also listen to his PodCast (www.hanselminutes.com)
RSS Feed : http://feeds.feedburner.com/ScottHanselman
MSDN Nuggets - not the stuff we eat ... its MSDN Nuggets
RSS Feed : http://www.microsoft.com/uk/msdn/nuggets/rss.aspx?t=all
Daniel Moth a Microsoft geek and a former MVP (lots of Screen Casts)
RSS Feed : http://feeds.feedburner.com/DanielMoth