Wednesday, February 13, 2013

Basic Command-lets

Folks , 

This blog is meant for learning power cli scripts . Going forward I will  be amending the scripts which we admins use on day today basis .

Some of the basic command-lets 

  1. Connect and disconnect from VC server

    Connect-VIServer VCserver -User admin -Password pwd 
    Disconnect-VIServer VCserver  -Confirm:$false
  2. Export report to CSV format
    Export-Csv $FileName
  3. Export report to HTML file
    $date=Get-Date
    $Folder= "c:\Temp"
    $FileName= "$Folder\Changehistory{0}{1:d2}{2:d2}.html" -f $date.Year,$date.Month,$date.Day
    $Report= @()
    ConvertTo-Html –title "ChangeHistory " –body "<H4>Date and time</H4>",$date -head $a  | Out-File $FileName
    $Report= Get-VIEvent
    $report | ConvertTo-Html -head $a -Body "<H4> VM guests Removed  - last 7 days  </h4>" | Out-File -append $FileName
  4. Email a report

    function SendMail{
    $sender = "sender@domain.com "
    $recipient = "Recipient@domain.com "
    $CC = "CCRecipient@domain.com"
    $BCC = "BCCRecipient@domain.com"
    $mailserver = "smtp.domain.com"
    $subject = "Change History "
    $body = "Report Attached"
    $msg = new-object System.Net.Mail.MailMessage $sender, $recipient, $subject, $body
    $attachment = new-object System.Net.Mail.Attachment $FileName
    $msg.CC.Add($CC)
    $msg.BCC.Add($BCC)
    $msg.Attachments.Add($attachment)
    $client = new-object System.Net.Mail.SmtpClient $mailserver
    $client.Send($msg)
    $attachment.Dispose()}
    SendMail

  5. Get Command-lets
    As the name say get command-lets are used to get the properties of the object.
  6. Set Command-lets

    These are used to set the attribute of a object



No comments:

Post a Comment