locked
Need to form a txt file RRS feed

  • Question

  • Hi Guys

      i have a txt file ,the contect as below

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

    APPData-CADD_RO_CNZJ

    APNET\USER1

    APNET\USER2

    APPData-CADD_RW_CNZJ

    APNET\USER3

    APNET\USER4

    ...............

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

    what i want was to conver it to a csv file like , can this possible ?

    APPData-CADD_RO_CNZJ   APNET\USER1

    APPData-CADD_RO_CNZJ   APENT\USER2

    APPdata-CADD_RW_CNZJ   APNET\USER3

    APPdata-CADD_RW_CNZJ   APNET\USER4

    

    

    • Moved by EugeneLeitanMVP Monday, October 31, 2016 6:37 AM it's not about the SCDPM
    • Moved by Bill_Stewart Friday, December 30, 2016 8:13 PM This is not "scripts on demand"
    Wednesday, June 18, 2014 9:09 AM

All replies

  • Hi Jacky,

    I know this was a while ago, I just saw it and thought I would have a go at it.

    Please see below.

    $contents = "APPData-CADD_RO_CNZJ","APNET\USER1","APNET\USER2","APPData-CADD_RW_CNZJ","APNET\USER3","APNET\USER4"
    #$contents = Get-Content C:\list.txt
    $APPData = $null
    foreach ($content in $contents) 
        {
        $user = $null
        if ($content -like "APPData*")
            {
            $APPData = $content
            }
        else
            {
            $user = $content
            }
    
        $output = New-Object -TypeName psobject -Property @{
                  Group=$APPData;
                  User=$user
                    }
            
        if ($user -eq $null)
            {
            }
        else
            {
            $output | Select-Object Group,User| export-csv -Append -Path c:\csv.csv 
            }
        }
    Thanks, Tim.

    Sunday, October 30, 2016 12:42 PM