Thursday, February 28, 2013

Send you the HTML file in email body through PowerShell

 This script will not send as a attachment, it will send you the HTML file in email body.


PowerShell
# Send email as a HTML body. 
$smtpServer = "SMTP Server Name" 
$MailFrom = "DL or Name of the person from where you need to send email" 
$mailto = "DL or Name of the person where you need to send email" 
$msg = new-object Net.Mail.MailMessage  
$smtp = new-object Net.Mail.SmtpClient($smtpServer)  
$msg.From = $MailFrom 
$msg.IsBodyHTML = $true 
$msg.To.Add($Mailto)  
$msg.Subject = "Report-Test." 
$MailTextT =  Get-Content  -Path C:\temp\Reports\Report.html 
$msg.Body = $MailTextT 
$smtp.Send($msg

VMware Power CLI Useful Scripts.


VMware Power CLI Useful Scripts

1. Collect OS information for all the Guest in a V Center.

Get-VM | Select Name,PowerState, @{N="GuestOS";E={($_ | Get-VMGuest).OSFullName}} | Export-Csv -NoTypeInformation -Path "Report.csv"

2. Collect Basic IP Address information for all the Guest in a V Center.

get-vm | select Name,@{N="IP Address";E={@($_.guest.IPAddress[0])}} | out-file ip.txt

3. Find Server Name, Host and CPU information for the Guest OS.

Get-VM | Select-Object Name, VMHost, NumCpu

4. Collect Inventory


@========OS INFO of VM===============================================

foreach ($vmView in (Get-View -ViewType VirtualMachine))
{
    $report += $vmView | Select-Object @{Name="VMHost"; Expression={(Get-View $vmView.Runtime.Host).Name}},
                                       @{Name="VMName"; Expression={$_.Name}},
                                       @{Name="GuestVersion"; Expression={$vmView.Guest.GuestFullName}}
}
$report | Sort-Object VMName -Descending | Export-Csv "vm_GuestVersion.csv" -NoTypeInformation


========================================================================

5. List all ESX host MAC addresses.


get-vmhost | get-vmhostnetworkadapter | export-csv d:\temp\VMHost.csv

6. List all guest VM MAC addresses

get-vm | get-networkadapter | export-csv d:\temp\VMAdapter.csv 

7. Collect Snapshot information's.

Get-VM | Get-Snapshot | Select-Object -Property Name, Description, Created, SizeGB | Format-List *

8. Script Signing.


Get-executionpolicy

Set-ExecutionPolicy AllSigned
Set-executionpolicy unrestricted
Set-executionpolicy remotesigned

9. Connect V-Center using power CLI

Connect-VIServer -User -Password

10. Disconnect V-Center

Disconnect-VIServer -Server  

11Get the VM data with Snapshot, Datastore, Total Disk Size, Cluster Name, OS Name


# To Get the VM data with Snapshot, Datastore, Total Disk Size, Cluster Name, OS Name 
Set-ExecutionPolicy Remotesigned -force 
if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) { 
Add-PSSnapin VMware.VimAutomation.Core} 
$VC1 = read-host "Type the VC name" 
$date = Get-Date -DisplayHint DateTime -Format "yyyy-M-d" 
Connect-VIServer -Server $VC1 -WarningAction SilentlyContinue 
Get-VM | Select Name,PowerState, @{N="SnapName";E={ 
($_ | Get-Snapshot).Name}},@{N="Datastore";E={ 
($_ | Get-Datastore).Name}},@{ N="TotalDisk"; E={  
($_ | Get-harddisk | measure-object -property CapacityKB -sum).Sum}},@{N="GuestOS";E={ 
($_ | Get-VMGuest).OSFullName}},@{N="Cluster";E={ 
($_ | Get-Cluster).Name}}| Export-Csv -NoTypeInformation -Path \\xyz\Reports\Report-$VC1-$Date.csv 
Disconnect-VIServer -server $VC1 -Force -Confirm:$false