How to test if a csv file is empty or not and email it?

Hi,
I am new to powershell scripting and i have a small task which is basically i have a csv file which will sometimes be empty(it will have header row even if its empty ) and sometimes it will have some rows of data.so basically i have to write a power shell
script which will look at the csv file and if its empty then do nothing if its not empty then email it to someone with the csv file attached to it?
Can someone please help me with it?
Thanks

Hi mike,
Yeah sure i will keep an eye on it ,and yeah coming back to your way of code.Here is the way i am doing it
If ((Import-Csv D:\App\ODS\File\Share\StoreTrafficException.csv).Count -gt 1)
       Send-MailMessage -To "[email protected]"
       -From "[email protected]"
       -Attachments D:\App\ODS\File\Share\StoreTrafficException.csv
       -Subject 'Check on this file'
       -SmtpServer "int-smtp1.jjill.com"
and if i run this one i get the following error :-
Missing expression after unary operator '-'.
At D:\App\Email.ps1:5 char:9
+        - <<<< Attachments D:\App\ODS\File\Share\StoreTrafficException.csv
    + CategoryInfo          : ParserError: (-:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator
And all the sendmail paramaters and values are correct because i am using the sameone in my other code which i said worked fine.Can you suggest me any changes on why its failing? Just want to know the reason and it would be great if i can have this way also.
Thanks

Similar Messages

  • How to force checked out CSV Files to open in Excel and not in Notepad

    Hi,
    I'm looking for some pointers / direction.
    .CSV files on SharePoint 2010 document library opens up in notepad by default. I did the DocIcon.xml CSV entry, changed the MIME type in IIS and did the IIS reset. Also on client computer CSV file is associated with MS Excel 2013. Now clicking a CSV file
    opens it up in MS Excel.
    Now a user checks out a CSV file and the same user clicks on the CSV file, the file is opening in notepad! If other users clicks on the same checked out file (checked out by the first user) it opens up in Excel for them. I've tried the 'Edit in Microsoft
    Excel' from the pop up menu but with same result.
    How can I force a checked out CSV file to open in MS Excel?
    Thanks

    1. Highlight one of the images and press cmd+i (or right click and select "Get info")
    2. Click the dropdown menu and select Photoshop (you might have to click "Other..." to find it.
    3. Then click "Change All" button below.
    You're going to have to do this with every different TYPE of image (e.g. jpeg, tiff etc) but once you've covered all the types you won't have the problem again.
    Hope this helps!

  • How do I compare two csv files and not disable the user if the username is found in the 2nd file using powershell?

    Hi Guys
    I have two csv files with the following headers and I need to import both files into the script to check whether the StaffCode is present in the Creation/Renewal of Contract csv in a DisableAccount Script so I can stop any action to disable the account as
    the staff has renewed the contract with the company so the account should not be disabled.
    However my accounts are still being disabled. I am not sure now to construct the query so that it detects that the account is to be left alone if the staffcode is present in both files
    I does recognize that the $staffcodeN in the renewal file matches the $staffcode in the termination file
    but still proceeds to disable or set an expiry date to the account anyway based on the termination file. 
    How do I stop it from doing that?
    1)In the Creation/Renewal of contract file the following headers are present
         -  TranCode,StaffCode,LastName,FirstName,SocialSecurityNo,DateJoin,Grade,Dept,LastUpdateDate,EffectiveDate
    2)In the Disable of contract file the following headers are present
        - TranCode,StaffCode,LastName,FirstName,SocialSecurityno,LastDateWorked,Grade,Dept,LastUpdateDate,
    My data is not very clean , I have a-lot of special characters such as = , ' ,/ and \ characters to remove first before i can compare the data
    Thanks for the help in advance.
    Yours Sincrely
    Vicki
    The following is a short snippet of the code 
    $opencsv = import-csv "D:\scripts\Termination.csv"
    $opencsv2 = import-csv "D:\scripts\RenewContractandNewStaff.csv"
    foreach ($usertoaction in $opencsv) 
    $Trancode = $usertoactionTranCode
    $StaffCode = $usertoaction.StaffCode.replace("=","").replace('"','')
    $LastName = [string]$usertoaction.LastName.Replace("/","\/").Replace(",","\,")
    $FirstName = [string]$usertoaction.FirstName.Replace("/","\/").Replace(",","\,")
    $socialsecurityno = $usertoaction.SocialSecurityNo.replace("=","").replace('"','')
    $DateJoin = $usertoaction.DateJoin.replace("=","").replace('"','')
    $LastDateWorked = $usertoaction.LastDateWorked.replace("=","").replace('"','')
    $Grade = [string]$usertoaction.Grade
    $Dept = [string]$usertoaction.Dept
    $LastUpdateDate = $usertoaction.LastUpdateDate.replace("=","").replace('"','')
    $AccountExpiry = [datetime]::Now.ToString($LastDateWorked)
    foreach ($usertoaction2 in $opencsv2) 
    $TrancodeN = $usertoaction2.TranCode
    $StaffCodeN = $usertoaction2.StaffCode.replace("=","").replace('"','')
    $socialsecurityNoN= $usertoaction2.SocialSecurityNo.replace("=","").replace('"','')
    $DateJoinN = $usertoaction2.DateJoin.replace("=","").replace('"','')
    $GradeN = [string]$usertoaction2.Grade
    $DeptN = $usertoaction2.Dept
    $LastUpdateDate = $usertoaction.LastUpdateDate.replace("=","").replace('"','')
    $EffectiveDate = $usertoaction.EffectiveDate.replace("=","").replace('"','')
    $LastName2 = [string]$usertoaction2.LastName.Replace(",", "").Replace("/","").trim()
    $FirstName2 = [string]$usertoaction2.FirstName.Replace("/","").trim()
    # Use DirectorySearcher to find the DN of the user from the sAMAccountName.
    $Domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
    $Root = $Domain.GetDirectoryEntry()
    $Searcher = [System.DirectoryServices.DirectorySearcher]$Root
    $Searcher.Filter = "(sAMAccountName=$samaccountname)"
    $doesuserexist1 = $Searcher.Findall()
    if ($doesuserexist1 -eq $Null)
    {Write-Host $samaccountname "account does not exist"}
    elseif ($StaffCodeN -match $staffcode)
    write-host "user has renewed the contract, no action taken"
    else
    if(($lastupdatedate -ne $null)-or($LastDateWorked -ne $null))
                        write-host "Setting Account Expiry to"$accountexpirydate
    #$ChangeUser.AccountExpires = $accountexpirydate
               #$Changeuser.setinfo()
    if ($UserMailforwarding -ne $null)
    #Set Account expiry date to Last Date Worked
    # $ChangeUser.AccountExpires = $accountexpirydate
    # $Changeuser.setinfo()
     write-host "staff" $displayname "with staff employee no" $samaccountname "has                          
    mailforwarding" 
    Write-host "Please disable the account manually via Active Directory Users & Computers and 
    Elseif ($accountexpirydate -lt $todaysdate)
    #disable the account

    Hi Vicki,
    This Forum has an insert-codeblock function. Using it will make your script far more readable
    Your script is missing some parts, it is impossible to follow the problem.
    You are performing the same string cleaning action on $opencsv2 for each element in $opencsv, when doing it once should suffice. Why not start it all by cleaning the values and storing the cleaned values in new arrays?
    The Compare-Object function is great, why not take it out for a stroll on these lists, it might just safe you lots of unnecessarily complicated code ...
    You are creating a new $Domain, $Root and $Searcher object each iteration, when doing it once should suffice. Probably not much of a time-saver, but every little thing contributes.
    Try pinpointing the problem by doing extensive logging, not only by writing which action was taken, but writing the inidividual information (variables, mostly) before evaluation occurs. Your if/elseif/else looks sound, so if it's still not doing what you
    want, the ingoing data must be different from what you think should be there.
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • How to generate a second csv file with different report columns selected?

    Hi. Everybody:
    How to generate a second csv file with different report columns selected?
    The first csv file is easy (report attributes -> report export -> enable CSV output Yes). However, our users demand 2 csv files with different report columns selected to meet their different needs.
    (The users don't want to have one csv file with all report columns included. They just want to get whatever they need directly, no extra columns)
    Thank you for any help!
    MZ

    Hello,
    I'm doing it usually. Typically example would be in the report only the column "FIRST_NAME" and "LAST_NAME" displayed whereas
    in the csv exported with the UTL_FILE the complete address (street, housenumber, additions, zip, town, state ... ) is written, these things are needed e.g. the form letters.
    You do not need another page, just an additional button named e.g. "export_to_csv" on your report page.
    The csv export itself is handled from a plsql procedure "stored procedure" ( I like to have business logic outside of apex) which is invoked by pressing the button "export_to_csv". Of course the stored procedure can handle also parameters
    An example code would be something like
    PROCEDURE srn_brief_mitglieder (
         p_start_mg_nr IN NUMBER,
         p_ende_mg_nr IN NUMBER
    AS
    export_file          UTL_FILE.FILE_TYPE;
    l_line               VARCHAR2(20000);
    l_lfd               NUMBER;
    l_dateiname          VARCHAR2(100);
    l_datum               VARCHAR2(20);
    l_hilfe               VARCHAR2(20);
    CURSOR c1 IS
    SELECT
    MG_NR
    ,TO_CHAR(MG_BEITRITT,'dd.mm.yyyy') AS MG_BEITRITT ,TO_CHAR(MG_AUFNAHME,'dd.mm.yyyy') AS MG_AUFNAHME
    ,MG_ANREDE ,MG_TITEL ,MG_NACHNAME ,MG_VORNAME
    ,MG_STRASSE ,MG_HNR ,MG_ZUSATZ ,MG_PLZ ,MG_ORT
    FROM MITGLIEDER
    WHERE MG_NR >= p_start_mg_nr
    AND MG_NR <= p_ende_mg_nr
    --WHERE ROWNUM < 10
    ORDER BY MG_NR;
    BEGIN
    SELECT TO_CHAR(SYSDATE, 'yyyy_mm_dd' ) INTO l_datum FROM DUAL;
    SELECT TO_CHAR(SYSDATE, 'hh24miss' ) INTO l_hilfe FROM DUAL;
    l_datum := l_datum||'_'||l_hilfe;
    --DBMS_OUTPUT.PUT_LINE ( l_datum);
    l_dateiname := 'SRNBRIEF_MITGLIEDER_'||l_datum||'.CSV';
    --DBMS_OUTPUT.PUT_LINE ( l_dateiname);
    export_file := UTL_FILE.FOPEN('EXPORTDIR', l_dateiname, 'W');
    l_line := '';
    --HEADER
    l_line := '"NR"|"BEITRITT"|"AUFNAHME"|"ANREDE"|"TITEL"|"NACHNAME"|"VORNAME"';
    l_line := l_line||'|"STRASSE"|"HNR"|"ZUSATZ"|"PLZ"|"ORT"';
         UTL_FILE.PUT_LINE(export_file, l_line);
    FOR rec IN c1
    LOOP
         l_line :=  '"'||rec.MG_NR||'"';     
         l_line := l_line||'|"'||rec.MG_BEITRITT||'"|"' ||rec.MG_AUFNAHME||'"';
         l_line := l_line||'|"'||rec.MG_ANREDE||'"|"'||rec.MG_TITEL||'"|"'||rec.MG_NACHNAME||'"|"'||rec.MG_VORNAME||'"';     
         l_line := l_line||'|"'||rec.MG_STRASSE||'"|"'||rec.MG_HNR||'"|"'||rec.MG_ZUSATZ||'"|"'||rec.MG_PLZ||'"|"'||rec.MG_ORT||'"';          
    --     DBMS_OUTPUT.PUT_LINE (l_line);
    -- in datei schreiben
         UTL_FILE.PUT_LINE(export_file, l_line);
    END LOOP;
    UTL_FILE.FCLOSE(export_file);
    END srn_brief_mitglieder;Edited by: wucis on Nov 6, 2011 9:09 AM

  • How to test the simple .java file in cactus

    dear friends,
    i have use the junit first time .And i am working in weblogic8.1 so i have use cactus .But i face the problem to use it.
    1. how to test the simple .java file in cactus.
    2.how to run the cactus in weblogic 8.1.

    Hi,
    It is because the converter works on byte code and it only supports a subset of the Java language (see the JC specifications). It is kind of like compiling you code on Java 6 and trying to run it on Java 5. The JCDK outlines the required compiler version.
    Cheers,
    Shane

  • How get output generated as csv file  by reading  by buffered reader and wr

    how get output generated as csv file by reading by buffered reader and writer

    String file_location = "C\temp\csv.txt");
    try {
         URL fileURL = getClass().getResource(file_location);
         if (fileURL != null){
              BufferedReader br = new BufferedReader(new InputStreamReader(fileURL.openStream()));
              String s = br.readLine();
              while (s != null)  {
                   if (!s.equals ("")) {
                        System.out.println(s);
                   s = br.readLine();
              br.close();
         else {
              // error
    catch (IOException ex){ex.printStackTrace();}rykk
    Message was edited by: a dummy
    rykk.

  • Help Me... How to get Data from CSV File...?

    Hi Everyone..!
    This is yajiv and am working in CS3 Photoshop platform. I know about Java Script. Is it possible to get the data from CSV files. Actually our client use to send us the CSV files which contains a lot of swatch name and reference files in one particular image name.
    Actually how we work on that CSV file is, first we copy file name to search that CSV file. then get the result to paste into layer name. This process continue till the end of swatch.
    Thank in Advance
    -yajiv

    > Is it possible to get the data from CSV files.
    Have you tried searching this forum?

  • Open hub destination problem - .csv file is empty

    Hi everyone,
    I am trying to extract data from our BW system using Open Hub Dest. to a .csv file
    DTP runs successfully means show total no. of records but when I see in AL11 then records are not in .csv file that is .csv file is empty.
    How to figure out the problem?
    Best regards
    Ahmad

    @Jagadeesh:
    if I correctly understood you, you mean to say that first I should run DTP and save to an excel file to see if it shows data or not. This i think is not possible; as when we create OHD then 'Destination Type' we can choose among 'DB table', 'table' and 'third party tool',
    so if I choose 'Table' then 'File Name' is .csv file (same name as the OHD) and can change it to .xls file
    @Arun:
    have permission to write in the folder
    Do you mean creating OH to a Database Table?
    in DTP I have a filter on a Characteristic, when its 1500 records then it works (data is in .csv file) but when 3500 records then .csv file is empty
    no error message, no log
    Regards
    Ahmad

  • How can I embed a pdf file into the body of an email?

    How can I embed a pdf file into the body of an email?

    The problem is defining what it even means to “embed” a PDF file in the body of an e-mail, especially if you are dealing with a multiple page PDF file.
    E-mail is either pure text, rich text (something akin to RTF in Word), or HTML. PDF is not compatible with any of these. Thus, to embed a PDF file, something has to be converted and that means the PDF would be converted to a less graphically rich raster format. But is that what you would really want?
    I think that the MacOS and iOS e-mail clients do under some circumstances place an attached PDF file within HTML segments and by clicking on same, you get the equivalent of extracting the full PDF file, but I have no real experience with that.
    Another alternative is HTML with a proxy image with a hyperlink to an external PDF file that is invoked when you click on the hyperlink.
    Perhaps you can explain what you are really trying to accomplish and what the recipient of such an e-mail's actual experience would be?
              - Dov

  • How can i send a PDF file to my i phone and be able to read it

    How can i send a PDF file to my i phone and be able to read it

    Use the free Adobe Reader for iPhone -> https://itunes.apple.com/us/app/adobe-reader/id469337564?mt=8.
    Clinton

  • How do I edit the contacts files on both my iPad and iPhone?

    How do I edit the contacts files on both my iPad and iPhone?

    Open Contacts, select a contact, then tap Edit in the upper right corner.

  • I am trying to export a Numbers spreadsheet to a csv file, but it does not put the commas in

    I am trying to export a Numbers spreadsheet to a csv file, but it does not put the commas in.  I want to use it with an HTML table generator tool, but the tool is looking for commas.   The Export to CSV exports it as a spreadsheet with all the formatting removed, and no commas.
    Here is the html table tool:
    http://www.textfixer.com/html/csv-convert-table.php

    Numbers '09 create CSV files with comma separated values if and only if your system is using decimal period.
    If the system is using decimal comma, the CSV files are created using semi-colon as separator.
    Yvan KOENIG (VALLAURIS, France)  dimanche 11 décembre 2011 11:11:25
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • How to copy the photo with file name at window 7 and search specific one in iphone 4s?

    How to copy the photo with file name at window 7 and search specific one in iphone 4s?

    Clendenen02 wrote:
    2) It would be equally helpful if there was something that would take the name of the picture file and spotlight comment, copy and paste it to a movie file's comments with the same name but obviously has different extention. For an example
    In a Pictures folder
    Name: Dark Knight, The.jpeg       Comment: (2008) Genre: Action...             <- copy comment
    In a Movie Folder
    Name: Dark Knight, The.m4v       Comment:                                               <- paste 
    and do this for all 700 files
    This Bash script will do it.
    Edit "PicDir" and "MovDir" to the location of your Folders
    (Note: The comment is written to the m4v file using xattr, so the Spotlight comment field appears blank in Finder, but the comment metadata is still indexed by Spotlight (If you add a Spotlight comment from Finder, it is stored both as an extended attribute and in a .DS_Store file)
    #!/bin/bash
    PicDir=$HOME/Desktop/Pictures
    MovDir=$HOME/Desktop/Movies
    for f in $PicDir/*
    do
         if [ ! -d "$f" -a "${f##*.}" == "jpeg" ]; then
              comment=$(mdls -raw -name kMDItemFinderComment "$f")
              if [[ $comment != "(null)" ]]; then
                   picname=${f##*/}
                   movname=${picname%.*}.m4v
                   if [ -e "$MovDir"/$movname ]; then
                         xattr -w com.apple.metadata:kMDItemFinderComment "\"$comment\"" "$MovDir"/$movname
                   fi
              fi
         fi
    done

  • How do I show my keynote file on a dvd player and control the slides?

    how do I show my keynote file on a dvd player and control the slides with the skip or next chapter command on the dvd remote? when I export to quicktime, it changes slides on a timed basis. I want the chapter button on a dvd remote to act like a mouse click would.

    Hi Robert
    You have to export the individual slides from your Keynote presentation, and then import them into your DVD application.
    I use DVDStudioPro - it works fine this. I'm sure iDVD will be OK.Going via QT has never worked for me.
    Regards Robert
    G4(7 y.o)1.5GHz 1.25 GB Ram, 2x120GB intHD, orig AGP & Radeon 9200 PCI card   Mac OS X (10.4.8)   2monitors, CRT TV, FCP5.0.4, DVDSP4.1.1, STP1.1, Comp2.3, LT2.1, QT7.1.3

  • I deleted the picture in iphoto, then emptied my iphoto trash, but the picture is still showing on my computer when i go into my trash under "all images" How do you delete pictures even when you empty the trash and they stay in the computer?

    I deleted the picture in iphoto, then emptied my iphoto trash, but the picture is still showing on my computer when i go into my trash under “all images” How do you delete pictures even when you empty the trash and they stay in the computer?

    Wtih iPhoto 9 when the iPhoto Trash is emptied the files get moved to the Trash bin in the Dock as a second chance to change your mind.  Look in the Dock's Trash bin.
    OT

Maybe you are looking for

  • 3 iOs 5 bugs no one seems to be talking about

    I've noticed 3 bugs in iOs 5 that no one seems to be talking about. 1.  Sometimes the setup personal hotspot toggle in settings will keep thinking even if you don't tap on it.  I believe this contributes to the poor battery life.  I've found the only

  • Apparently I don't understand a feature correctly in Mac mail version 6.6

    I am a little confused about what the difference is between a new mailbox and a new smart mailbox in mail. I wanted to create one folder that I can put all my mail into so that I can use my inbox as a sort of a "tickler file". I created a new "mailbo

  • TargetName error when trying to start in-process server

    I just put in a fresh install of Forms and Reports on a server. Everything started up ok except for my in-process reports server, which just refuses to start. When I went to see if it was giving any errors (it isn't, which is odd...), I noticed a dif

  • File Upload/Menu Select Option

    I have a form that needs to have a combination of a file upload or a menu select option. The client I have been working with wants to use an insert form to insert a new record. If the file that they want doesn't have the filename their looking for in

  • Provide Edit WebI reports authorization with Save as option.

    Hello Experts, I am new to BO authorizations. I have a scenario where i need to provide my users Edit rights(not modify) and provide them with Save As access while denying the save access(So that they don't overwrite the original report with their ch