none
PowerShell - Combine 2 Functions outputs to 1 single csv file RRS feed

  • Question

  • Hello,

    Is there a not to complicated way to combine the output of 2 PowerShell functions into a single csv file?

    For Example:

    NOTE: This NOT the actual functions of what i am trying to do so please do not simply tell me to write the 2 functions into another separate function. I am aware that i can do that. This question is to gain knowledge in my scripting abilities and expand my thinking when writing. Thank You !


    I have a large script filled with several different functions.

    Function1

    I have a function that we'll call function1 that gathers AD properties regarding "password info" and is exported to a csv file which fills in 3 columns and populates the rows with AD data.

    Function CheckPassword {#PW is expired\last set
        [CmdletBinding()]
        Param(
            [Parameter(Mandatory=$true)]
            [string[]]$accounts
        )
    foreach ($account in $accounts)
            {
    		
    	$var = Get-LDAP $account
            $domain =    $var.distinguishedName.ToString().split(",")[2] -replace "dc="
            $adobject = Get-ADUser $account -Server $domain -Properties "PasswordExpired", "PasswordLastSet", "msDS-UserPasswordExpiryTimeComputed"| Select-Object -Property "SamAccountName", "PasswordExpired", "PasswordLastSet", @{Name=“ExpiryDate”;Expression={[datetime]::FromFileTime($_.“msDS-UserPasswordExpiryTimeComputed”)}}
    		
    		 
    		
           $adobject |export-csv "C:\passcheck\PassExpiry$((Get-Date).ToString('MM-dd-yyyy')).csv" -NoTypeInformation -append
    
    $adobject

    This works great giving me exactly what i need in a csv file.


    Function2

    Now there is also a second function i have we'll call Function2

    This one is just a large IF \ IFESLE \ IFESLE \ IFESLE \ IFESLE  type script that i have designed to spit out custom words with the same aliases i feed it depending on if something is true or false.


    that also works as expected.

    Here is the dilemma...

    How can i run Funtion1 and include data from Function2 into the csv file? Also notice that Function2 does not have a header in the csv file picture. That is because as of now i run Function1 to create the CSV file then i run Function2. Once Function2 has spit out the data in the PowerShell console, I copy it from powershell ISE then paste it into the csv file that Function1 created.

    The end goal is something like this without the extra steps of running the second function and having to manually copy and paste.


    My thinking is that i should somehow be able to call Function2 into Function1 and add that data into "Column E" in the CSV file without having to run Function2 separately and copy paste the results.

    Any thoughts? (hoping I explained this well)

    • Moved by Bill_Stewart Friday, July 7, 2017 6:18 PM Unanswerable drive-by question
    Monday, May 15, 2017 6:49 PM

All replies

  • Your question is very convoluted and not possible to decode.

    You have to functions and no relationship between them.  How can you manage to join the data.

    For data to be "aligned" (joined) it must contain a relationship between the two data sets.

    There is no such thing as "call one function into another function".

    Before you embark on this quest you first need to learn about PowerShell and about data.  Learning PowerShell will get you a step closer to learning data.

    There is no such CmdLet as "Get-LDAP".

    If you are just trying to do a line by line assignment then loop through both arrays and add them together.

    $both = for($I = 0;$I -lt $a1;$I__}
        $a1[$I] +,a2[$I}
    }


    \_(ツ)_/



    • Edited by jrv Monday, May 15, 2017 8:47 PM
    Monday, May 15, 2017 8:44 PM
  • Get-LDAP Cmdlet in PowerShell

     http://www.netcmdlets.com/support/articles/netcmdlets-get-ldap-cmdlet-in-powershell/


    Monday, May 15, 2017 10:59 PM
  • It is not a native PowerShell CmdLet and is from a third party.

    I happen to have 30+ years of system programming experience.  I stand by my statements. You need to learn about data and PowerShell.

    The CmdLet is not needed if you are using AD CmdLets but if you like it then OK.

    You still cannot directly join to lists of any kind except as I posted.


    \_(ツ)_/

    Monday, May 15, 2017 11:17 PM