Powershell Day 13

Day 13 Other   

XML:

Powershell support XML, as XML is a language which works great for windows, and it’s like a platform independent, you can create a webpages using xml.

With Powershell we can use Export-Clixml cmdlet to convert an output to xml format.

Remoting:

It require PowerShell v2

Enable_remoting

help about_remote_troubleshooting

EnterPSSession  -computer –computername

 

EnterPSSession  -computer -computername (get‐content names.txt)

Email:

Email can be done using one of the following:

  1. Outlook
  2. .Net
  3. SNTP

 

  1. Outlook

$Outlook = New-Object .-com Outlook.Application

$Inbox = $Outlook.Session.GetDefaultFolder(6)

 $Inbox.items | foreach { write-host $_.Subject }

 

  1.  For .Net

System.Net.Mail

System.Net.Mail.MailMessage

System.Net.Mail.SmtpClient

System.Net.Mail.Attachment

 

 

$Email = New-Object System.Net.Mail.MailMessage( “Info@contoso.local”, “administrator@contoso.local”)

 

  1. SMTPClient

 

Coloring:

You can define coloring at the output as well

PS C:\> write-host -Fore Red “Powershell” -Back Green

More properties/methods:

If you see the get-member of any cmdlets you may get some properties/methods but that may not be complete to get the complete list of properties and methods use the Format List (fl) option with * .

|Fl*

Profile:

As you know if you declare any variable or script anything that will be valid (available ) until you are using the session, once you close the Powershell session your variables will be lost, to keep the variable  or object for longer use, declare it at profile which loads at the time of Powershell start

To get the profile location there is a variable called “PROFILE”

PS C:\> variable profile |fl *

Name        : PROFILE

Description :

Value       : C:\Documents and Settings\<user>\My Documents\WindowsPowerS

              hell\Microsoft.PowerShell_profile.ps1

Options     : None

Attributes  : {}

Generally profile will be at location

 C:\Documents and Settings\<user>\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

*Will try to update it further.

About these ads
This entry was posted in Powershell and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s