4

I am getting different out for the same powershell command and I am not sure why.

When this runs within a function, I get output 1 and when I run by itself I get output2

New-Item -Path C:\DEPL\nichdwww\deployments\Full\bob3 -type directory

Output 1

PSPath            : Microsoft.PowerShell.Core\FileSystem::C:\DEPL\nichdwww\deployments\Full\bob3
PSParentPath      : Microsoft.PowerShell.Core\FileSystem::C:\DEPL\nichdwww\deployments\Full
PSChildName       : bob3
PSDrive           : C
PSProvider        : Microsoft.PowerShell.Core\FileSystem
PSIsContainer     : True
Name              : bob3
Parent            : Full
Exists            : True
Root              : C:\
FullName          : C:\DEPL\nichdwww\deployments\Full\bob3
Extension         : 
CreationTime      : 6/23/2015 2:14:39 PM
CreationTimeUtc   : 6/23/2015 6:14:39 PM
LastAccessTime    : 6/23/2015 2:14:39 PM
LastAccessTimeUtc : 6/23/2015 6:14:39 PM
LastWriteTime     : 6/23/2015 2:14:39 PM
LastWriteTimeUtc  : 6/23/2015 6:14:39 PM
Attributes        : Directory
BaseName          : bob3
Mode              : d----

Output 2

Directory: C:\DEPL\nichdwww\deployments\Full


Mode                LastWriteTime     Length Name                                                                                                                         
----                -------------     ------ ----                                                                                                                         
d----         6/23/2015   2:45 PM            bob3

Here is the function

function ArchiveFullSolution($wsp)
{
    $ParentPath=Split-Path $wsp.DirectoryName -Parent
    $FullPath=$ParentPath+'\Full\'
    $Fullfilename=$FullPath+$wsp.Name
    #$Fullfilename

    #does file exist    
    if(Test-Path -path $Fullfilename)
    {
        #Make Full Archive folder
        #$script:Makefolder
        if($script:Makefolder)
        {
            #does folder exists
            $DayFormat=Get-Date -f yyyy-MM-dd
            if(Test-Path -path $FullPath$DayFormat)
            {
                write-host "folder $FullPath$DayFormat exists"
                $DayTimeFormat=Get-Date -f yyyy-MM-dd-hh-mm
                 write-host "Creating folder $FullPath$DayTimeFormat"
                New-Item -Path $FullPath$DayTimeFormat -type directory

                $script:Makefolder=$false
                $script:FullArchivePath=$FullPath+$DayTimeFormat
            }
            else
            {
                write-host "no folder exists"
                write-host "Creating folder $FullPath$DayFormat"
                New-Item -Path $FullPath$DayFormat -type directory 

                $script:Makefolder=$false
                $script:FullArchivePath=$FullPath+$DayFormat
            }
        }

        #move file into archive
        Move-Item $Fullfilename $script:FullArchivePath
        write-host "Moving file $($Fullfilename) to $FullArchivePath"        
    }
    #copy file into full
    Copy-Item $wsp.FullName $FullPath
    write-host "Copying file $($wsp.FullName) to $FullPath"
}
Barry MSIH
  • 3,525
  • 5
  • 32
  • 53
  • 1
    I got the second output for both (ie: if I just run the cmd or if I call a function with the cmd inside). – TroyAndAbed Jun 23 '15 at 19:29
  • 2
    Looks like a `Format-List *` to me. PowerShell displays object in a certain way... unless you override it. – Matt Jun 23 '15 at 19:45

1 Answers1

3

Check your function. Most likely it is outputting another object first. After the PowerShell F&O (formatting and output) engine sees one type of object it wants to format everything after that like that type. If it then sees another type of object, it will fall back to using Format-List IIRC.

Tony Hinkle
  • 4,706
  • 7
  • 23
  • 35
Keith Hill
  • 194,368
  • 42
  • 353
  • 369