Friday, August 31, 2012

Setting Microsoft Office 2012 Trust Center's Trusted Location Paths using Powershell.

Hi Everyone.

If you are working in a Telecom Industry, and if your Analysts and Consultants are using in house built templates then i am sure that you are 98% facing the “Trust Centre warning”.

We are using custom in house built Office Templates for Word,Excel, and PowerPoint.  and the problem was whenever we open our in house templates is Office 2012 we were facing the below error.

We can click on it but it is a quite annoying.

31-08-2012 14-47-12

To resolved this error, the solution is to add our custom built templates directory to the  trusted location in trust center manually on every laptop and desktop.

31-08-2012 15-14-10

Did i mentioned MANUALLY???

Naaaaaa !!!!!!! I thought that we can script this.

And to resolve this is wrote a simple script. you can download the script from this link :
http://gallery.technet.microsoft.com/scriptcenter/Setting-office-2010-31d6a5f4

This script is very simple.,

You only need to provide the path of your templates or the location which you want to add as trusted to  $trustlocation variable.
$trustlocation = 'C:\Mylocation\Templates'
and that’s all , when you run the script , the script will create a location registry  named as “Location99” in to the registry.
and the Registry Keys will be look like this .
31-08-2012 15-33-48
and i have added comments in the script for easy understanding,
Functionality.
  1. First script test the path of the “Location99” registry key
  2. and if the Test path fails that will create a New Registry  Folder “Location99” and the the following registry keys
      • AllowSubfolders this is DWORD registry key and the value is 1 to allow subfolders as a trusted location too.
      • Date  = Date of creation
      • Description = Description for location etc.
      • Path  =  Path to the folder
  3. and if folder found it just write a confirmation message in the console that folder do exists.
  4. The script will do the same process for WORD,EXCEL and Powerpoint.
After running the script the location is added to the Word.
31-08-2012 15-15-24

Thanks
Aman Dhally
join aman on facebook Join aman on Linkedin follow aman on Twitter

Tuesday, August 28, 2012

Birthdays and Bill payments reminder script based on Powershell.

Hi,

My memory is very weak , and sometime i do forget the birthdays of my friends. and sometime even if forget to pay my mobile bills, I do have set up reminders on my mobile and outlook but still sometime i missed the alerts.

On weekends i hardly check my mobile until it is ringing and on Laptop at home i wont use outlook. Due to my laziness i mainly forget these things. But one thing i do most of the days are open my powershell console daily. the profile on my office laptop and home laptop are synced and script between both laptops are synced daily.

So i thought why not to create a simple script which open daily with my powershell console and show me if i need to pay any bill payment today or to wish  birthday to any of my friend.

I liked the thought. the only problem was to manually add everyone’s birthday in to the script, but somehow i able to manage it.

Download script form here http://gallery.technet.microsoft.com/scriptcenter/BirthdaysTasksBill-cfb1d958

Script is very simple and i used SWITCH statement in it.  There are two parts in the script, first is Payment part and second the the Birthday part.

Payment Part:
We have to make payment every month, so in payment part script only check for date and if date matched as per your criteria it shows what you have defined.
Birthday Parts:
Birthdays are specified by months and Date, the birthday part script check for month and the it switch to date.
How to use it.
Add your friends birthday manually and adding birthday and reminders are one time task.
28-08-2012 19-53-47
When you run the script, it checks for Month, and if it matched the current month then it switch again to Day of the Month, in below example if the Month is 1 means January then it switch to day of the Month, and if the day of Month matches toy 27 then that will shows the predefined alert in the console.
28-08-2012 19-50-11
Screenshots.
09-09-2012 19-01-11
24-08-2012 19-00-3720-09-2012 19-02-29
28-08-2012 19-31-57
The best way to use this script to add it to your Powershell $profile.So that whenever you open your Powershell Console you can have alerts.
20-09-2012 19-03-07

Download script form here http://gallery.technet.microsoft.com/scriptcenter/BirthdaysTasksBill-cfb1d958


Thanks
Aman Dhally
join aman on facebook Join aman on Linkedin follow aman on Twitter

Wednesday, August 22, 2012

Software Inventory of Remote Machines/Servers using Powershell.

Hi,

Sometime i think that my Powershell is based on TASK Based, i think my most of the post are related to “How to do that and how to achieve and ease that task with Powershell”, isn’t ?.

 The tittle of my blog is “The Life of an IT administrator”, and i love to share what this I.T. life shows me everyday, some days are like clam and peaceful and some someday we are like fire fighters.

Anyways today there is need arise that i need to create a report of Software Installed on every Server, for me this is a very tough JOB { if you do manually }, you can imagine that RDP to every server, open Control Panel and Programs and features, and do it manually…i don’t like this….but what you have to do, you have do , there is no choice…..

But

Thanks GOD we have PowerShell.

I have write down a tiny script which can do this task for us and export the data in to nicely formatted HTML file.

You can define multiple server name separated by commas, and this script will create a single HTML file that contains list of all software installed on each server.

Download Script from here : http://gallery.technet.microsoft.com/scriptcenter/Software-Inventory-using-f2870b19

How to use script.
  1. Run Powershell as Administrator.
  2. After the name of the script type the name of the servers those software details you want to know.
  3. The output file will be saved to your D:\ Drive.
Note.: This script wont run for windows 2003 Severs,
I tested this script for Windows 2008 Servers and Windows 7 machine.
22-08-2012 13-23-36
22-08-2012 13-25-03
Download Script from here : http://gallery.technet.microsoft.com/scriptcenter/Software-Inventory-using-f2870b19

Thanks
Aman Dhally
join aman on facebook Join aman on Linkedin follow aman on Twitter

Tuesday, August 21, 2012

Powershell &Active Directory : Active Directory Reports in Excel.

Hi,

Active Directory reporting, some time we thinks what should a Active Directory reports contains, should i need a tool to do that reporting job? or should i purchase a active Directory tool to do this task.

One of my friend want an Active Directory Reporting tool and he was planning to buy it, i asked what are your requirements, he told me that, I want a tool which can export a data in to the Excel, and i have a list of disabled Computer accounts, User Account so that i can delete them,

I told this that that can be done easily with powershell and for him i wrote a little powershell script. this script is based on RSAT , Active Directory module. Make sure you have RSAT tools installed before running the script.

when you run the script , that will Import Active Directory Module First and then open an Excel workbook. In excel you can find 4 sheets for now. they are contains
  1. List of inactive Users Accounts
  2. List of inactive Computer Accounts
  3. Users Accounts created within a period of week.
  4. List of Users with password never expires enabled.
Script Download link : http://gallery.technet.microsoft.com/scriptcenter/Active-Directory-Reports-bb8c1cc7

21-08-2012 13-19-01
and this excel file will be saved on users Desktop.

Script Download link : http://gallery.technet.microsoft.com/scriptcenter/Active-Directory-Reports-bb8c1cc7

Thanks
Aman Dhally
join aman on facebook Join aman on Linkedin follow aman on Twitter

Thursday, August 16, 2012

Powershell & active directory : Find all AD users account those are created between predefined period of time.

Hi,

Reporting,Monitoring and the Documentation are few of the major tasks which most of the IT admin does like me. If you know how to do scripting it saves lots of time. For all IT guys those primarily works on Windows Platform for them i think learning of Powershell is must, because if you know Powershell you can automate or script most of the daily to daily tasks. 

Powershell is like  Swiss Army knife.

My todays task was to create a list of all active directory users account those are created within a week. It is easy but worth sharing.

Make sure you have RSAT tools installed before running the Active Directory based cmdlets.

Today is 16 August and i want to find a users those are create within a week so if we minus 7 days we got 9 August, so we want to know how many users created with-in the time period of 9th - 16 August.

Lets Start.

First we need to import Active Directory module.

Import-Module -Name ActiveDirectory 

300420122321033


Now we need to define date. The date will be sever days earlier, this is easy we just need to minus 7 days from the current date. Get-Date support a method .AddDays by which you can add or minus days.

$week = (Get-Date).AddDays(-7)

when you run the $week variable we can get a 7 days earlier date.


16-08-2012 18-58-11


Good. Now our next step is to find users. Now we are going to use Get-ADUser , and then using -Filter * to search and find all users, and we are using -Properties * so that it expand all properties of the user, and then we are piping the output to where cmdlet and then are are choosing only those users from the output who’s $_.whenCreated property is greater then or Equal to $week.

Get-ADUser -Filter * -Properties * | where { $_.whenCreated -ge $week }


We have the output now., but lets format a more little bit.


16-08-2012 19-02-03


let add more one more pipe to the command, pipe it to select Cmdlet and choose to show only, Name and When Created Property.

Get-ADUser -Filter * -Properties * | where { $_.whenCreated -ge $week } | select Name,whenCreated

Not is looks nice isn’t ?


16-08-2012 19-15-39


Powershell Script for this.



To make this task more easy , i have create a powershell script which can do this task, and the script with export all the users Name, When created to a CSV file and save that on your Desktop.


You can download the script from this link : https://dl.dropbox.com/u/17858935/AD_Users_Created_WithIn_Predifined_Perios.zip 


Thanks

Aman Dhally

join aman on facebook Join aman on Linkedin follow aman on Twitter

Tuesday, August 14, 2012

FaceBook module for Powershell.

Hi,
In the world of Powershell everything Blue. Powershell community is fill with lots of amazing thinkers, developers and contributors. There are lots of nice peoples who spend day and night on writing a script and then give them to the community to use it freely. There are lots of other peoples too who are very active on Powershell Forms , you just need to as a question and i am sure that you will hear from any of them soon.
One the module i like in powershell is “Facebook Powershell Module” which are created by “Jon Newman”.
The first question came in mind  why to use this module? and the Answer is, It is Cool, it is geeky and it is more then a module.
lets think about a scenario, for example.
  1. You can write a simple script which contain a list of all of your friends birthday date and that script run everyday,and using Facebook module you can wish them on their Facebook account and you never miss anyone birthday.
  2. If you are running a group , page and love to share “Quote of the Day”, then create a list of 365 quotes and post them automatically using Facebook module.
  3. If your wife /girlfriend is angry with you and complaining that you don't give her time, to impress her  just collect few love quotes and post it on her wall in every one hour ;o)
Powershell is all about automation, lets automate the Facebook. ;o)
I am using a Facebook module to post a message on my Facebook wall when any of my server fails.  Logically we created a new Facebook account for this and we added that Facebook account as friend {all IT admins}, and there are few scripts which runs every night and in case they found anything worn they post a message on their walls and in the morning we all can see it.
Lets Start.
You can download the module from this link “http://facebookpsmodule.codeplex.com/”  and the current version of module is “FacebookPSModule Alpha 0.6.3” .
Download the module and save it on your desktop.
13-08-2012 18-16-12
this is a zip file extract it and run the “FacebookPsModule Aplha 0.6.3.msi”
13-08-2012 18-17-20
A welcome window will be open “Click on Next”
14-08-2012 11-49-54
The default folder to save the module file in “WindowsPowershell” located in My Document or Documents, Leave it as it is and click on “Next”
14-08-2012 11-50-04
Installation starts.
13-08-2012 18-17-34
Installation Complete , click on “Close”
13-08-2012 18-18-18
You can verify that Facebook Module has copied to the “Documents\WindowsPowershell\Module\Facebook “
13-08-2012 18-18-56
Now lets open powershell and import the module.
Import-Module facebook
13-08-2012 18-19-25
and let’s see which comdlets it has.
Get-Command -Module Facebook
Wow!!!!!
13-08-2012 18-20-06
Let run the Cmdlet New-Connection to connect to the Facebook …
New-FBConnection

errr, error ….
13-08-2012 18-25-52

The New-FBConnection cmdlet runs only in STA mode, you have to do this one .

Lets run Powershell in STA mode.

Open Run and type “Powershell.exe –STA” and click on OK.

13-08-2012 18-25-59

when powershell windows open. Import Facebook Module once again and run New-FBConnection

14-08-2012 12-08-50

when you run the New-FBConnection cmdlet a Facebook login windows will open.

13-08-2012 18-26-11
Now provide your Email ID and password and make sure that you checked on “Keep me logged in” and then click on “Log In”

13-08-2012 18-26-35
and now a Facebook app page will open , click on “Log in With Facebook”

13-08-2012 18-27-31
Now the module is ask for Permission and just click on “Allow”.

13-08-2012 18-27-45

after you clicked on allow, all is done and you will see this . that means connection with your Facebook account is successful.
13-08-2012 18-28-03
we have to enter these Login Details once only { i tested this with multiple reboots of my machine i am able to access the Facebook account without enter user credentials } , as per Facebook Module documentation,,  “Once you create an “access token”, it will by default be cached in %LOCALAPPDATA%\FacebookPowerShellModule_CachedToken.txt, so you will not have to re-enter it as long as you use your current user account.”
Okeis. now lets test it. using New-FBFeed cmdlet.
New-FBFeed -Message "this is a test message"
13-08-2012 18-31-13
and the result is.
Bingo Smile 
13-08-2012 18-31-05
Now next step it to automate it.

i wrote a simple script to test it .

This script Import Facebook Module first, and it will test the connectivity of all the servers those are defined in $servers and if the connection to the server is successful it just wrote and message in the console and it the connection is unsuccessful then it wrote on Facebook Wall. 

Import-Module Facebook
New-FBConnection 
$servers =  "Dc-local","Not-Exists"

foreach ( $server in $servers ) {
if (test-Connection -ComputerName $Server -Count 2 -Quiet ) { 
write-Host "$Server is alive and Pinging " -ForegroundColor Green
} else
{
New-FBFeed -Message "$Server seems dead not pinging"
}
} 

When i run the script the output was below. My Dc-Local is live and Not-Exists is not so the below output is showing me the Facebook FeedID

13-08-2012 18-54-33
Now lets check the Facebook wall.
Yo!! Our server was not reachable and we sucessfully posted that message to the Wall.. Smile
13-08-2012 18-54-53
We successfully automated the Facebook using powershell.
Thanks
Aman Dhally
join aman on facebook Join aman on Linkedin follow aman on Twitter