Showing posts with label New-Object. Show all posts
Showing posts with label New-Object. Show all posts

Sunday, November 15, 2015

PowerShell & Microsoft Word 2016 : Opening Word 2016 Desktop Application using PowerShell.

 

In my office, we have some "Word Wizards" , the "CHOSEN ONES" those write add-ins for Microsoft Office applications. Mainly Ms-Office add-ins written in either, in-built visual.net code or by using VSTO in visual studio.

Last week, I have an friendly argument with one of "Wizard"  in my office, about, PowerShell and Word. I told him, that we can do almost anything with PowerShell and He said " Can you Automate Office applications?" and I replied as "YES" (OOPS).

And that, the day, when our battle started, he keep asking me to to do this and that, and I was trying to figure out "How to do that", sometimes, if feels like "Gandalf" and "Dumbledore" are fighting with each other.

3489253-1dumbledore

But, these fighting ( not literally)  comes out as very educating and for me :) . So, I planned to write articles about it. I am sure, that you will learn something from this too.

Today, we are going to see, that how can we open Microsoft Word using PowerShell.

Our first task is to open Microsoft word, and we are going to use the COM object for it. Name of the Word's COM object is "Word.Application". and we have to use the New-Object cmdlet, to map com object to the variable.

$word = New-Object -ComObject "Word.Application"

 

After that, we have to set the Visible property of $word as true, otherwise we won't be able to see word.

 

$word.Visible = $true

 

After that, we jus need to type our variable $word and hit enter to open Microsoft Word.

 

Aman Dhally - Manya Kaur

You may see a lot's of Output after  running $word variable, you can omit that output by adding pipe and Out-Null variable.

$word | Out-Null

 

In , next blog post we will see, we will deal with word documents :) , Stay tunes for more, and thanks for reading the blog post.

 

Aman Dhally - Manya Kaur

 

With Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

Monday, August 10, 2015

PowerShell Tip : Set Desktop Application Vertically or Horizontally using PowerShell.

 

In the previous blog post we have seen , that how can we minimise all desktop applications using PowerShell.

While exploring the Shell.Application , I have found two another cool methods, One is to Tile all open application Horizontally and  and another  is to tile all open windows application Vertically.

In the below code we are doing the same, creating a new COM Object using New-Object cmdlet and adding the Shell.Application com object to $a variable.

After creating $a variable, now try to run the TileHorizontally() and TileVertically()  methods and see the magic,

$a = New-Object -ComObject  Shell.Application

$a.TileHorizontally()

$a.TileVertically()

04-08-2015 15-12-34

04-08-2015 15-46-59

I am hoping that you will enjoy it.

Aman Dhally Manya Kaur

Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

Wednesday, August 5, 2015

PowerShell Tips : Minimize all Desktop Application using PowerShell.

 

In the pervious PowerShell Tip, we have seen that how can create a new empty PowerShell script on the fly.

Ok, today's tip is little bit exciting. Do you what happens when you press Windows Key + D ?

Yes, it, minimise everything. I was trying to achieve the same using PowerShell, and manage to do it. Smile 

Wanna know it? I can tell you, but you have to promise me a coffee ;o) .

It's simple we have to use the New-Object and need to add Shell.Application to a variable and then we need to run the MinimizeAll() method. Simple!

$a = New-Object -ComObject  Shell.Application

$a.MinimizeAll()

 

Aman Dhally - Manya Kaur

Try it now and have fun.

Aman Dhally Manya Kaur

Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.