none
compose a PowerShell script that will pull data from a text file RRS feed

  • Question

  • Read the text file line-by-line. Assume each line has the following format:
     
    Employee Name,Address Line 1,Address Line 2,City,State,Postal Code,Work Phone.
     
    So for instance, one line might be:
     
    John Smith,214 Empire Lane,Apartment 123,Honolulu,HI,12345,555-555-5555
     

    You then need to sync the data you pull for each employee into Active Directory (matching the data in the text file to the corresponding AD attributes). Remember to add in logic to check if the data from the database  table matches Active Directory – if so, then no update of that attribute needs to be performed.

    I have to create this script but I do not actually have the txt file I will be pulling data from, just the sample from above. I just need to know how the process works and how I could do this. I also have a txt file that was given but i do not know what it is for. I will include it here also below.

    Please help me with this, I desperately need to figure it out as soon as possible!

    Thanks guys

    ##################
    ##Mystery Script##
    ##################


    $ServerName= "EXCHANGESERVER.domain.com"

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$ServerName/PowerShell/ -Authentication Kerberos
    Import-PSSession $Session

    function sendEmail
    {  
        param([string]$subject, [string]$body, [string]$to, [string]$from, [string]$cc)
        [System.Reflection.Assembly]::Load("System.Web, Culture=Neutral, Version=2.0.0.0, PublicKeyToken=b03f5f7f11d50a3a") | out-null
        $email = new-object System.Web.Mail.MailMessage
        $email.To = $to
        $email.From = $from
        $email.Subject = $subject
        $email.CC = $cc
        $email.BodyFormat =  [System.Web.Mail.MailFormat]::HTML
        $email.Body = $body
        [System.Web.Mail.SmtpMail]::SmtpServer = "smtp.domain.com"
        [System.Web.Mail.SmtpMail]::Send($email)
    }

    $strTopHTML = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD W3 HTML//EN""><html><body>"
    $strEndTableHTML = "</table>"
    $strEndHTML = "</body></html>"
    $tableHTML = "<table border=1 cellspacing=0 cellpadding=5 bordercolor=#808080><tr><td bgcolor=#000080 align=center colspan=2>"
    $tableHTML += "<b><font face=Verdana size=2 color=#FFFFFF>Mystery Script"
    $tableHTML += "</font></b></td></tr><tr><font color=#000080><td>Column 1</td><td>Column 2</td></font></tr>"
    $emailBody = ""

    $MaxItems = 50

    $mailboxes = Get-Mailbox -ResultSize Unlimited

    $mbStatistics = $mailboxes | Get-MailboxFolderStatistics -FolderScope Calendar
    $mbStatistics += $mailboxes | Get-MailboxFolderStatistics -FolderScope Contacts
    $mbStatistics += $mailboxes | Get-MailboxFolderStatistics -FolderScope Inbox
    $mbStatistics += $mailboxes | Get-MailboxFolderStatistics -FolderScope SentItems

    $mbStatistics | Sort-Object ItemsInFolder -Descending | Select-Object -first $MaxItems | % {
        $folder = $_.identity
        $numItems = $_.itemsinfolder
        $tableHTML += "<tr><td>$folder</td><td>$numItems</td></tr>"
    }

    $emailBody = $strTopHTML + $tableHTML + $strEndTableHTML + $strEndHTML

    sendEmail -subject "Mystery" -body $emailBody -to "bob@domain.com" -from "reports@domain.com"


    Tuesday, July 3, 2012 6:10 PM

All replies