Formatting Output from two command help needed

Welcome Forums General PowerShell Q&A Formatting Output from two command help needed

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 8 months ago.

  • Author
  • #5276

    Topics: 1562
    Replies: 0
    Points: 0
    Rank: Member

    by link12 at 2012-11-14 10:23:04

    I'm running into issues with formatting the output of this script in particular to the FullName property of a
    get-childitem cmdlet. The first couple of variables formats the full path to just a small set of info, just the samaccount name
    of the predefined file. I then take that $filename variable and loop to get the primary smtp address. This all works.
    What I want for out is the following.

    Read through a directory that has PST files, pull out the name, get the smtp address, and then get the full path to the pst file.

    I have the, but can't get the fullname path

    Format should output to a text file that looks like the following., c:\folder\username01.pst, c:\folder\username02.pst, c:\folder\username03.pst

    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
    Set-ADServerSettings -ViewEntireForest $true

    $filepath = "C:\testfile"

    $filename = get-childitem $filepath | foreach-object {($_.BaseName -split "-")[3]}
    $filenamepath = get-childitem $filepath | ForEach-Object {$_.FullName}

    foreach ($i in $filename){
    $smtpaddress = get-mailbox $i | select primarysmtpaddress
    $smtpaddress,filenamepath (the filenamepath is not working)

    Remove-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

    by DonJ at 2012-11-15 04:18:32

    So, I think you just may have a few logic errors.

    Get-ChildItem c:\testfile |
    Select @{n='Filename';e={$_.Name},@{n='Path';e={$_.FullName},@{n='SMTP';e={Get-Mailbox $_.Name | Select -Expand PrimarySMTPAddress}}

    Is that not what you're after? Or am I not understanding the question?

    In your code, within the ForEach loop, $filenamepath is a collection of objects, but you're treating it like a single object. I think that might be why this isn't working for you – you're kind of mixing and matching bits. What I tried to do is put all of that into a single consistent command. I don't have Exchange so I can't test it, and I'm not 100% clear on what you're after, but hopefully it'll help a bit...

    by link12 at 2012-11-15 05:54:37

    Basically I'm building a manifest file to ingest PST files to an archive system. We're going to have a central file server that stores the PST files with a common name. I need to first parse that name so that I can do a get-mailbox on it to get the PrimarySMTPAddress. I also need the FullName to get the path.

    Folder example PST format (This will have hundreds)

    Output needed for a text file., c:\test\pst_storage\Something-Something-Something-samaccountname1.pst, c:\test\pst_storage\Something-Something-Something-samaccountname2.pst, c:\test\pst_storage\Something-Something-Something-samaccountname3.pst

    I tried your example on a file and go the following. Thanks for the help.

    The hash literal was incomplete.
    At C:\Users\usertest01\Desktop\test.ps1:2 char:155
    + Get-ChildItem $path | Select @{n='Filename';e={$_.Name},@{n='Path';e={$_.FullName},@{n='SMTP';e={Get-Mailbox $_.N
    | Select -Expand PrimarySMTPAddress}} < <<<
    + CategoryInfo : ParserError: (CloseBraceToken:TokenId) [], ParseException
    + FullyQualifiedErrorId : IncompleteHashLiteral

The topic ‘Formatting Output from two command help needed’ is closed to new replies.