Announcement

Collapse
No announcement yet.

powershell script and CSV formatting

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • powershell script and CSV formatting

    $a = Get-ChildItem C:\Scripts\Reports\USuserInfoAll.csv
    Foreach ($x in $a) {$x.delete()}
    [ADSI]"ldap://LDAP1"
    Connect-QADService -Service 'domain1
    $days=7
    $old = (Get-Date).AddDays(-$days)
    Get-QADUser -Disabled -SizeLimit 0 -ErrorAction SilentlyContinue -IncludedProperties employeeNumber | where {($_.employeenumber -ne $null) -and
    ($_.employeenumber -ne "pending") -and ($_.employeenumber -ne "contractor") -and ($_.employeenumber -ne "service account") -and ($_.employeenumber -ne
    "contractor ") -and ($_.ModificationDate -gt $old) } | ft 'employeeNumber'| out-File C:\Scripts\reports\USuserInfoAll.csv -append
    [ADSI]"ldap://LDAP2"
    Connect-QADService -Service 'domain2'
    Get-QADUser -Disabled -SizeLimit 0 -ErrorAction SilentlyContinue -IncludedProperties employeeNumber | where {($_.employeenumber -ne $null) -and
    ($_.employeenumber -ne "pending") -and ($_.employeenumber -ne "contractor") -and ($_.employeenumber -ne "service account") -and ($_.employeenumber -ne
    "contractor ") -and ($_.ModificationDate -gt $old) } | ft 'employeeNumber'| Out-File C:\Scripts\reports\USuserInfoAll.csv
    #Disconnect and fall back to default domain
    Disconnect-QADService



    The script runs successfuly (it appends teh results from 2 domains). However the output is seen as :

    employeenumber
    -------------------------------------------------------
    123065
    256986

    employeenumber
    -------------------------------------------------------
    987560
    986580

    I would like the output to be seen as given below

    THE_OUTPUT
    IDENTIFIER ID
    123065 1
    256986 1
    987560 1
    986580 1


    How do i achieve this formatting in the output?
    P.S a) THE_OUTPUT should be the first line (text) in the output (cell A1 in
    excel)
    b) IDENTIFIER and ID should be the second line (text) in the output
    (cell A2 and A3 in excel)
    c) Third line onwards should show the employeenumber (in cell A3) and
    '1' (in cell B3 in excel)

  • #2
    Re: powershell script and CSV formatting

    Can any scripting GURU help me?

    Comment


    • #3
      Re: powershell script and CSV formatting

      s_anr
      Please don't bump your post
      We are a community of volunteers who give up our free time to help here. No reply in just over a day is perfectly reasonable (as is no reply at all to some questions)
      If you really need help on a fixed timescale, phone Microsoft and raise a support incident. Unless you have Technet or MAPS this will cost you, so have a credit card ready

      Now looking at your problem, I think it comes down to the use of the out-file -append command
      You will need to build up a string for each line, check if it is valid (i.e. ignore "employeenumber" and "---------"), then append , 1 to the string and write THAT to your CSV

      Alternatively, how about an Excel macro to process the CSV you already have?
      Tom Jones
      MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
      PhD, MSc, FIAP, MIITT
      IT Trainer / Consultant
      Ossian Ltd
      Scotland

      ** Remember to give credit where credit is due and leave reputation points where appropriate **

      Comment


      • #4
        Re: powershell script and CSV formatting

        Ossian,

        Sorry if my second follow up was offending. It wasn't meant to be. I was just hoping if someonce can gimme a clue.

        Comment

        Working...
        X