Friday, October 28, 2011

“Windows Powershell 2.0 Bible”

 

Hi,

Today the postman delivered the two brand new copies of book  “Windows PowerShell 2.0 Bible” published by “John Wiley & Sons, Inc.” and written by “Thomas Lee”, “ Karl Mitschke” , “Mark E. Schill” and “Tome Tanasovski”.

IMG_0042

This Book send to us by “Mark E. Schill”

From the behalf of “New Delhi PowerShell user Group” Thanks a lot  “Mark E. Schill” and also thanks to  “Wiley Publications” too to send a complimentary copy of it ..

you can purchase the Book in India from flipkart: http://www.flipkart.com/books/1118021983?pid=0fx3fb371e&_l=GOondWnomHOpT1nYHiHhRg--&_r=Me02lPU3E3R%20JZUOhY7ZAA--&ref=e86a7d5b-b871-424b-9041-610e5362b060

and if you are out of India then you can purchase from Amazon: http://www.amazon.com/Windows-PowerShell-2-0-Bible-Thomas/dp/1118021983/ref=sr_1_1?ie=UTF8&qid=1319806233&sr=8-1

 

Enjoy reading :)

Thanks

Aman Dhally

Friday, October 21, 2011

How to run Powershell commands in “cmd”


Hi,
Sometime you want  to run PowerShell commands in Batch (.bat) files or may be from old command shell (cmd.exe) due to some specific needs or you may want to replace your old dos based email program with “ Send-MailMessage” , and you was thinking how to do it , let me show to you :)

comand prompt
So let’s Do it !!!!!
Step.1
Open “Command Prompt”
  • Go to “RUN” {Windows Key + R }
  • Type “CMD”
  • RUN Box
  • Now on “Command Prompt” type “Powershell.exe <cmdlet Name>”
    • For Example: “PowerShell.exe Get-Process”
Bingo!!!!!!!
It’s working perfectly J

Thanks
Aman Dhally

Thursday, October 20, 2011

Generate System Information Reports using WMI and PowerShell

 

Hi Guys,

Do you ever want to see what going on users machines? or what Settings he have on his system,?

If you have few users in your office then you can go to there desk and check it manually, but –whatif ? you have hundreds on users or you are supporting a remote users.

I just came to same problem when i want to support a remote users and he don’t know how to run “Task manager”, how to open “RUN” dialogue box so that we can run “Msconfig” to view the list of soft wares which are on system startup list , and the internet connection was very low at his end and i can’t be able to do anything remotely.

To overcome from this situation I wrote a little script which get the system info and put everything in a HTML file and when when script done it open the HTML file in Internet Explorer. Then you can ask user to send that HTML file to you by email.

This script is using “WMI” queries to find the information , using get-wmiobject command and the covert everything to HTML using “Convertto-Html” cmdlet and save the output in to a file.

 

Currently the the HTML report contains .

  1. BIOS Information
  2. Physical Disk Drives
  3. List of Network Adapters
  4. Operating System Information
  5. Logical Disk Drives
  6. IP Addresses for each Network Card
  7. List of Startup softwares
  8. Running Processes
  9. List of Services [ Whose “startup” mode is set  “Automatic” but they are currently “Stopped” for some reason]

 

you can also add more “wmi” queries in to the script. like, Battery info, CDROM Drive info, Printer info etc in to it.

I tested the script on “Windows7” and it is working perfectly.

The output of the script will be found at : C:\Users\USERNAME\Computername.html

you can download the whole script from here : http://dl.dropbox.com/u/17858935/SystemInformation.zip

Screenshot:

SystemInfo

Hope you like it

Thanks

aman dhally

Tuesday, October 18, 2011

How to run Child PowerShell Process in PoweShell

 

Hi Guys,

may be you are wondering what is its meaning, it mean how we can use PowerShell with in a PowerShell as a child process

It is very useful when we want to call a cmdlets or script within PowerShell Script.

Syntax

Syntax is Simple type PowerShell following by Curly Braces and in Curly braces you can provide any script, or cmdlet.

PowerShell  { }

for example  open PowerShell console and type the below command:

powershell {Get-ChildItem c:\}

ChildPowerShell process0

How we know that its the above command running as Child Process not as a same process.

okays I have a proof.

Currently there is  only one “PowerShell.exe ”  process is running.[fig.1]

ChildPowerShell process  fig.1

 

now execute our command as let’s see what happens [fig.2]

ChildPowerShell process 2 fig.2

now see below when we execute the script a new child “PowerShell.exe” process starts beneath our old “PowerShell.exe” process and when it done executing it the child process will exit automatically [fig.3]

ChildPowerShell process 3 fig.3

 

hope u like it :)

thanks

aman dhally

Send HTML formatted email using PowerShell


Hi Guys,
Did you ever tried to send HTML formatted colour coded email using PowerShell ? I was trying to do it but didn’t get any good and useful information on it, but i finally manage to get it done.
So lets start:
For example i am sending a test email from my official account to my GMAIL account.
 the script will look like  this:

##############  Script start Here ##########
# $smtp variable contain the name/ip of your email server ##
# $to contain the email id whom you want to send email ###
# $from contain email of sender ###
# $Subject contain subject of the email.
# In Body we are defining some HTML coding in to our email message body
# <b> means BOLD
#<br> means Break go to next Line
#<a href> provide a link to the text
# <font color=red> , give the color to the font
$smtp = "Exchange-Server"
$to = "Aman Dhally <amandhally@gmail.com>"
$from = "Aman Singh <aman.dhally@analysysmason.com>"
$subject = "This is a Test of HTML Email"

$body = "Dear <b><font color=red>$to</b></font> <br>"
$body += "We are testing <b>HTML</b> email <br>"
$body += "Click <a href=
http://www.google.com>here</a> to open google <br>"
#### Now send the email using \> Send-MailMessage
send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high
########### End of Script################

Note: Make sure you use –BodyasHtml parameter in Send-MailMessage otherwise it send as plain text format.
Now lets see how this email will look like :)
Send-MailMessage
Cool!!! it look exactly how we have define it in our Script :)
you can find more HTML coded which you can use in script from here http://www.w3schools.com/html/default.asp

take care
aman dhally

“End-of-Parameters (--)” in PowerShell

 

Hi guys,

sorry for posting after a long time :( ..

Today I was reading something and found a interesting parameter named as “End-Of-Parameters” which in represented by “double hyphens” ( – – ) .

what is the usage ?

When we use End-of-Parameters in a command or in a script after it takes every thing as argument even they looks are parameters.

example

If you want to write –Message in Write-Warning cmdlet  as a string which is also a parameter, there are two ways to do it.

1. using double quotes (“”)

Write-Warning -Message "-Message"

End-of-parameters1

and we can also do the same with using “End-of-Parameters”

2. using End-of-Parameters

Write-Warning -Message -- -Message

End-of-parameters2

 

cool isn’t :) 

Take care

Aman Dhally