PowerShell New-Item output is inconsistent - Why? - powershell

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"
}

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.

Related

How do I open a folder link in powershell/windows terminal?

When I type the obvious thing
PS > cd folderName.lnk
or
PS > cd folderName.lnk
in both cases it claims that the file doesn't exist, even though 'ls' shows that it does. Any suggestions? Thank you
try this:
$sh = New-Object -ComObject WScript.Shell
$target = $sh.CreateShortcut('<full-path-to-shortcut>').TargetPath
set-location -LiteralPath $target
make sure you use the full path to the shortcut, not a relative path like .\FolderName.lnk
you can also script it so you always get the absolute path:
$shortcut = '.\Shortcut.lnk'
$absolutepath = Convert-Path -Path $shortcut
$sh = New-Object -ComObject WScript.Shell
$target = $sh.CreateShortcut($absolutepath).TargetPath
Set-Location -LiteralPath $target
As noted by others, .lnk files are not directories,...
Get-ChildItem -Path "$env:USERPROFILE\Desktop"
# Results
<#
Directory: C:\Users\WDAGUtilityAccount\Desktop
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/2/2023 1:39 PM 737 Scripts.lnk
#>
...so you cannot directly navigate to them with any directory-like command.
The Desktop is the folder for that file.
(Get-ChildItem -Path "$env:USERPROFILE\Desktop").Fullname
# Results
<#
C:\Users\WDAGUtilityAccount\Desktop\Scripts.lnk
#>
Get-ChildItem -Path "$env:USERPROFILE\Desktop" |
Select-Object -Property '*'
# Results
<#
PSPath : Microsoft.PowerShell.Core\FileSystem::C:\Users\WDAGUtilityAccount\Desktop\Scripts.lnk
PSParentPath : Microsoft.PowerShell.Core\FileSystem::C:\Users\WDAGUtilityAccount\Desktop
PSChildName : Scripts.lnk
PSDrive : C
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
Mode : -a----
VersionInfo : File: C:\Users\WDAGUtilityAccount\Desktop\Scripts.lnk
InternalName:
OriginalFilename:
FileVersion:
FileDescription:
Product:
ProductVersion:
Debug: False
Patched: False
PreRelease: False
PrivateBuild: False
SpecialBuild: False
Language:
BaseName : Scripts
Target : {}
LinkType :
Name : Scripts.lnk
Length : 737
DirectoryName : C:\Users\WDAGUtilityAccount\Desktop
Directory : C:\Users\WDAGUtilityAccount\Desktop
IsReadOnly : False
Exists : True
FullName : C:\Users\WDAGUtilityAccount\Desktop\Scripts.lnk
Extension : .lnk
CreationTime : 1/2/2023 1:39:41 PM
CreationTimeUtc : 1/2/2023 9:39:41 PM
LastAccessTime : 1/2/2023 1:39:43 PM
LastAccessTimeUtc : 1/2/2023 9:39:43 PM
LastWriteTime : 1/2/2023 1:39:41 PM
LastWriteTimeUtc : 1/2/2023 9:39:41 PM
Attributes : Archive
#>
So, you have to extract that FQDN from the link and use the available directory/Name commands to navigate to that path.

How to find the title for a PDF from the metadata?

How can I get the title for a PDF file after having renamed the file itself?
PSPath : Microsoft.PowerShell.Core\FileSystem::/home/nicholas/to/99.pdf
PSParentPath : Microsoft.PowerShell.Core\FileSystem::/home/nicholas/to
PSChildName : 99.pdf
PSDrive : /
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
Mode : -----
ModeWithoutHardLink : -----
VersionInfo : File: /home/nicholas/to/99.pdf
InternalName:
OriginalFilename:
FileVersion:
FileDescription:
Product:
ProductVersion:
Debug: False
Patched: False
PreRelease: False
PrivateBuild: False
SpecialBuild: False
Language:
BaseName : 99
Target :
LinkType :
Length : 592483
DirectoryName : /home/nicholas/to
Directory : /home/nicholas/to
IsReadOnly : False
FullName : /home/nicholas/to/99.pdf
Extension : .pdf
Name : 99.pdf
Exists : True
CreationTime : 2/19/2021 11:45:18 PM
CreationTimeUtc : 2/20/2021 7:45:18 AM
LastAccessTime : 2/20/2021 2:02:36 AM
LastAccessTimeUtc : 2/20/2021 10:02:36 AM
LastWriteTime : 2/19/2021 11:45:18 PM
LastWriteTimeUtc : 2/20/2021 7:45:18 AM
Attributes : Normal
PS /home/nicholas/to>
PS /home/nicholas/to> Get-ChildItem -Path ./ –File | Select-Object -Property *
This is to bulk import PDF files into calibre, which, notably, seems to recognize duplicates and even displays some titles. Is it parsing the PDF file itself, or gleaning this from meta-data?
For this, you can use pdfinfo.exe which you can find as part of the free Xpdf command line tools.
After you have downloaded and extracted the zip file, copy pdfinfo.exe to some directory and make sure you unblock it, either by right-click or by using PowerShell
Unblock-File -Path 'Where\Ever\You\Have\Copied\It\To\pdfinfo.exe'
Using that, to get the original title as stored in the pdf, you do
$title = ((& 'D:\Test\pdfinfo.exe' 'D:\Test\test.pdf' |
Where-Object { $_ -match '^Title:' }) -split ':', 2)[-1].Trim()

Rename-Item throwing error when path contains '>'

When I try to rename a path that contains '<' or '>' i get the
Illegal characters in path error. Strangely Rename-Item can handle other special characters like '#'.
I refuse to belive that rename-item can't handle the '<' char. Does it needs to be escaped somehow?
I'm using the Get-FolderItem cmdlet instead of Get-ChildItem (due to pathlength restrictions on gci) and passing Rename-Item a object with a fullname prop like so
Edit: I'm a noob, it's › and not >
Rename-Item -LiteralPath $fileWithChar.FullName -NewName $newNameWithoutChar
Both $filleWithChar and $newNameWithoutChar are strings.
I've tried using both -path and literalPath and it still throws the error.
robocopy is a Unicode application on demand, see following Logging options switches:
/unicode : Display the status output as Unicode text
/UNILOG:file : Output status to Unicode Log file (overwrite)
/UNILOG+:file : Output status to Unicode Log file (append)
Below is improved Get-FolderItem.ps1 script. Pay your attention to changes:
line 135 $params.AddRange(#("/L", … ,"/R:0","/W:0"))
changed $params.AddRange(#("/L", … ,"/R:0","/W:0","/UNILOG:robolog.txt"))
line 158 Invoke-Expression $Script | ForEach {
changed Invoke-Expression $Script | Out-Null; Get-Content robolog.txt | ForEach {
Sample output proves Unicode awareness (some names are pretty nonsensical, sorry):
PS D:\PShell> . D:\Downloads\Get-FolderItem.ps1
PS D:\PShell> $x=Get-ChildItem -path "D:\bat\UnASCII Names\*" | Get-FolderItem
WARNING: D:\bat\UnASCII Names\ěščřžýáíé.txt is not a directory and will be skipped
PS D:\PShell> $x.FullName
D:\bat\UnASCII Names\MathBoldScript (𝓜𝓪𝓽𝓱𝓑𝓸𝓵𝓭𝓢𝓬𝓻𝓲𝓹𝓽)\Mathematical Bold Script.txt
D:\bat\UnASCII Names\Türkçe (Türkiye)\çğüşöıĞÜİŞÇÖ\ĞÜİŞÇÖçğüşöı.txt
D:\bat\UnASCII Names\‹angles›\‹angles›.txt
PS D:\PShell>
Improved script uses an auxiliary file:
Function Get-FolderItem {
<#
.SYNOPSIS
Lists all files under a specified folder regardless of character limitation on path depth.
.DESCRIPTION
Lists all files under a specified folder regardless of character limitation on path depth.
.PARAMETER Path
The type name to list out available constructors and parameters
.PARAMETER Filter
Optional parameter to specify a specific file or file type. Wildcards (*) allowed.
Default is '*.*'
.PARAMETER ExcludeFile
Exclude Files matching given names/paths/wildcards
.PARAMETER MaxAge
Exclude files older than n days.
.PARAMETER MinAge
Exclude files newer than n days.
.EXAMPLE
Get-FolderItem -Path "C:\users\Administrator\Desktop\PowerShell Scripts"
LastWriteTime : 4/25/2012 12:08:06 PM
FullName : C:\users\Administrator\Desktop\PowerShell Scripts\3_LevelDeep_ACL.ps1
Name : 3_LevelDeep_ACL.ps1
ParentFolder : C:\users\Administrator\Desktop\PowerShell Scripts
Length : 4958
LastWriteTime : 5/29/2012 6:30:18 PM
FullName : C:\users\Administrator\Desktop\PowerShell Scripts\AccountAdded.ps1
Name : AccountAdded.ps1
ParentFolder : C:\users\Administrator\Desktop\PowerShell Scripts
Length : 760
LastWriteTime : 4/24/2012 5:48:57 PM
FullName : C:\users\Administrator\Desktop\PowerShell Scripts\AccountCreate.ps1
Name : AccountCreate.ps1
ParentFolder : C:\users\Administrator\Desktop\PowerShell Scripts
Length : 52812
Description
-----------
Returns all files under the PowerShell Scripts folder.
.EXAMPLE
$files = Get-ChildItem | Get-FolderItem
$files | Group-Object ParentFolder | Select Count,Name
Count Name
----- ----
95 C:\users\Administrator\Desktop\2012 12 06 SysInt
15 C:\users\Administrator\Desktop\DataMove
5 C:\users\Administrator\Desktop\HTMLReportsinPowerShell
31 C:\users\Administrator\Desktop\PoshPAIG_2_0_1
30 C:\users\Administrator\Desktop\PoshPAIG_2_1_3
67 C:\users\Administrator\Desktop\PoshWSUS_2_1
437 C:\users\Administrator\Desktop\PowerShell Scripts
9 C:\users\Administrator\Desktop\PowerShell Widgets
92 C:\users\Administrator\Desktop\Working
Description
-----------
This example shows Get-FolderItem taking pipeline input from Get-ChildItem and then saves
the output to $files. Group-Object is used with $Files to show the count of files in each
folder from where the command was executed.
.EXAMPLE
Get-FolderItem -Path $Pwd -MinAge 45
LastWriteTime : 4/25/2012 12:08:06 PM
FullName : C:\users\Administrator\Desktop\PowerShell Scripts\3_LevelDeep_ACL.ps1
Name : 3_LevelDeep_ACL.ps1
ParentFolder : C:\users\Administrator\Desktop\PowerShell Scripts
Length : 4958
LastWriteTime : 5/29/2012 6:30:18 PM
FullName : C:\users\Administrator\Desktop\PowerShell Scripts\AccountAdded.ps1
Name : AccountAdded.ps1
ParentFolder : C:\users\Administrator\Desktop\PowerShell Scripts
Length : 760
Description
-----------
Gets files that have a LastWriteTime of greater than 45 days.
.INPUTS
System.String
.OUTPUTS
System.IO.RobocopyDirectoryInfo
.NOTES
Name: Get-FolderItem
Author: Boe Prox
Date Created: 31 March 2013
Version History:
Version 1.5 - 09 Jan 2014
-Fixed bug in ExcludeFile parameter; would only work on one file exclusion and not multiple
-Allowed for better streaming of output by Invoke-Expression to call the command vs. invoking
a scriptblock and waiting for that to complete before display output.
Version 1.4 - 27 Dec 2013
-Added FullPathLength property
Version 1.3 - 08 Nov 2013
-Added ExcludeFile parameter
Version 1.2 - 29 July 2013
-Added Filter parameter for files
-Fixed bug with ParentFolder property
-Added default value for Path parameter
Version 1.1
-Added ability to calculate file hashes
Version 1.0
-Initial Creation
#>
[cmdletbinding(DefaultParameterSetName='Filter')]
Param (
[parameter(Position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[Alias('FullName')]
[string[]]$Path = $PWD,
[parameter(ParameterSetName='Filter')]
[string[]]$Filter = '*.*',
[parameter(ParameterSetName='Exclude')]
[string[]]$ExcludeFile,
[parameter()]
[int]$MaxAge,
[parameter()]
[int]$MinAge
)
Begin {
$params = New-Object System.Collections.Arraylist
$params.AddRange(#("/L","/S","/NJH","/BYTES","/FP","/NC","/NDL","/TS","/XJ","/R:0","/W:0","/UNILOG:robolog.txt"))
If ($PSBoundParameters['MaxAge']) {
$params.Add("/MaxAge:$MaxAge") | Out-Null
}
If ($PSBoundParameters['MinAge']) {
$params.Add("/MinAge:$MinAge") | Out-Null
}
}
Process {
ForEach ($item in $Path) {
Try {
$item = (Resolve-Path -LiteralPath $item -ErrorAction Stop).ProviderPath
If (-Not (Test-Path -LiteralPath $item -Type Container -ErrorAction Stop)) {
Write-Warning ("{0} is not a directory and will be skipped" -f $item)
Return
}
If ($PSBoundParameters['ExcludeFile']) {
$Script = "robocopy `"$item`" NULL $Filter $params /XF $($ExcludeFile -join ',')"
} Else {
$Script = "robocopy `"$item`" NULL $Filter $params"
}
Write-Verbose ("Scanning {0}" -f $item)
Invoke-Expression $Script | Out-Null
Get-Content robolog.txt | ForEach {
Try {
If ($_.Trim() -match "^(?<Size>\d+)\s(?<Date>\S+\s\S+)\s+(?<FullName>.*)") {
$object = New-Object PSObject -Property #{
ParentFolder = $matches.fullname -replace '(.*\\).*','$1'
FullName = $matches.FullName
Name = $matches.fullname -replace '.*\\(.*)','$1'
Length = [int64]$matches.Size
LastWriteTime = [datetime]$matches.Date
Extension = $matches.fullname -replace '.*\.(.*)','$1'
FullPathLength = [int] $matches.FullName.Length
}
$object.pstypenames.insert(0,'System.IO.RobocopyDirectoryInfo')
Write-Output $object
} Else {
Write-Verbose ("Not matched: {0}" -f $_)
}
} Catch {
Write-Warning ("{0}" -f $_.Exception.Message)
Return
}
}
} Catch {
Write-Warning ("{0}" -f $_.Exception.Message)
Return
}
}
}
}

How do I output only the value of a property (without the property name)?

I'm dabbling in PowerShell again. My experience thus far has been limited to file operations typically found in old school DOS batch files (build folder structures, copy files, append to a file, etc.).
The following outputs a property label ("TotalSeconds") and its property value ("12.3456").
Measure-Command { c:\_foo\test.txt c:\_bar } | select TotalSeconds
How do I output only the property value ("12.3456")?
Thanks!
The Select-Object cmdlet has an -ExpandProperty parameter that will return the property's value:
Measure-Command { c:\_foo\test.txt c:\_bar } |
Select-Object -ExpandProperty TotalSeconds
Wrap the whole command in parentheses, and use the dot operator to access the property name.
Give this a shot:
(Measure-Command { c:\_foo\test.txt c:\_bar } | select TotalSeconds).TotalSeconds;
Or even more simply:
(Measure-Command { c:\_foo\test.txt c:\_bar }).TotalSeconds;
You can use the -ExpandProperty option on the Select-Object cmdlet. Here's a real-life example.
I want to add cl.exe from the MSVC toolchain to my path, so I can compile C programs from the Windows CMD prompt and PowerShell. I never remember the full path because it's buried in the application folder.
I do remember the path to the application folder though, so I assign it to a variable and use Get-ChildItem and Select-Object with a few options you may not have seen yet*.
_
Here is the example:
<0.o> $d="c:\program files (x86)\microsoft visual studio"
<0.o> get-childitem -path $d -filter 'cl.exe' -force -recurse -erroraction silentlycontinue|select -expandproperty directory|select -expandproperty fullname
C:\program files (x86)\microsoft visual studio\2019\Community\SDK\ScopeCppSDK\vc15\VC\bin
C:\program files (x86)\microsoft visual studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\Hostx64\x64
C:\program files (x86)\microsoft visual studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\Hostx64\x86
C:\program files (x86)\microsoft visual studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\Hostx86\x64
C:\program files (x86)\microsoft visual studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\Hostx86\x86
This task confused me at first, because I tried to go straight from this:
> get-childitem -path $y -filter "cl.exe" -recurse -erroraction silentlycontinue -force|select directory
Directory : C:\program files (x86)\microsoft visual
studio\2019\Community\SDK\ScopeCppSDK\vc15\VC\bin
Directory : C:\program files (x86)\microsoft visual
studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\Hostx64\x64
Directory : C:\program files (x86)\microsoft visual
studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\Hostx64\x86
Directory : C:\program files (x86)\microsoft visual
studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\Hostx86\x64
Directory : C:\program files (x86)\microsoft visual
studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\Hostx86\x86
to this:
> get-childitem -path $y -filter "cl.exe" -recurse -erroraction silentlycontinue -force|select -expandtab directory
Name : bin
CreationTime : 7/26/2021 12:47:05 AM
LastWriteTime : 7/26/2021 12:47:06 AM
LastAccessTime : 9/29/2021 9:32:55 AM
Mode : d-----
LinkType :
Target : {}
Name : x64
CreationTime : 7/26/2021 12:49:02 AM
LastWriteTime : 7/26/2021 12:50:09 AM
LastAccessTime : 9/29/2021 9:32:55 AM
Mode : d-----
LinkType :
Target : {}
Name : x86
CreationTime : 7/26/2021 12:49:02 AM
LastWriteTime : 7/26/2021 12:50:09 AM
LastAccessTime : 9/29/2021 9:32:55 AM
Mode : d-----
LinkType :
Target : {}
Name : x64
CreationTime : 7/26/2021 12:48:55 AM
LastWriteTime : 7/26/2021 12:50:09 AM
LastAccessTime : 9/29/2021 9:32:55 AM
Mode : d-----
LinkType :
Target : {}
Name : x86
CreationTime : 7/26/2021 12:48:54 AM
LastWriteTime : 7/26/2021 12:50:09 AM
LastAccessTime : 9/29/2021 9:32:55 AM
Mode : d-----
LinkType :
Target : {}
Yikes! Adding -ExpandTab to my previous command didn't give me what I wanted. Let's back up and use the Get-Module command (gm) to look at the objects in my pipeline:
> get-childitem -path $y -filter "cl.exe" -recurse -erroraction silentlycontinue -force|select -expandproperty directory|gm
TypeName: System.IO.DirectoryInfo
Name MemberType Definition
---- ---------- ----------
LinkType CodeProperty System.String LinkType{get=GetLinkType;}
Mode CodeProperty System.String Mode{get=Mode;}
Target CodeProperty System.Collections.Generic.IEnumerable`1[[...
Create Method void Create(), void Create(System.Security...
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRe...
CreateSubdirectory Method System.IO.DirectoryInfo CreateSubdirectory...
Delete Method void Delete(), void Delete(bool recursive)
EnumerateDirectories Method System.Collections.Generic.IEnumerable[Sys...
EnumerateFiles Method System.Collections.Generic.IEnumerable[Sys...
EnumerateFileSystemInfos Method System.Collections.Generic.IEnumerable[Sys...
Equals Method bool Equals(System.Object obj)
GetAccessControl Method System.Security.AccessControl.DirectorySec...
GetDirectories Method System.IO.DirectoryInfo[] GetDirectories()...
GetFiles Method System.IO.FileInfo[] GetFiles(string searc...
GetFileSystemInfos Method System.IO.FileSystemInfo[] GetFileSystemIn...
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetObjectData Method void GetObjectData(System.Runtime.Serializ...
GetType Method type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
MoveTo Method void MoveTo(string destDirName)
Refresh Method void Refresh()
SetAccessControl Method void SetAccessControl(System.Security.Acce...
ToString Method string ToString()
Attributes Property System.IO.FileAttributes Attributes {get;s...
CreationTime Property datetime CreationTime {get;set;}
CreationTimeUtc Property datetime CreationTimeUtc {get;set;}
Exists Property bool Exists {get;}
Extension Property string Extension {get;}
FullName Property string FullName {get;}
LastAccessTime Property datetime LastAccessTime {get;set;}
LastAccessTimeUtc Property datetime LastAccessTimeUtc {get;set;}
LastWriteTime Property datetime LastWriteTime {get;set;}
LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;}
Name Property string Name {get;}
Parent Property System.IO.DirectoryInfo Parent {get;}
Root Property System.IO.DirectoryInfo Root {get;}
BaseName ScriptProperty System.Object BaseName {get=$this.Name;}
I spy a FullName property that looks promising, bringing me to the final version I showed up top.
_
*For options you have not seen, pop open a powershell and type:
get-help get-childitem -showwindow
or
get-help select-object -showwindow
and use the search bar at the top of the window that appears to search for the option you want.

Why does PowerShell output change after loading assembly?

I am getting some unusual output from New-Item in a script if I've first loaded an assembly with reflection. Why?
If I run
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
New-Item -Path "temp" -ItemType directory
I get the following odd output from New-Item:
PSPath : Microsoft.PowerShell.Core\FileSystem::C:\Users\swoogan\Desktop\temp
PSParentPath : Microsoft.PowerShell.Core\FileSystem::C:\Users\swoogan\Desktop
PSChildName : temp
PSDrive : C
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : True
Name : temp
Parent : Desktop
Exists : True
Root : C:\
FullName : C:\Users\swoogan\Desktop\temp
Extension :
CreationTime : 7/28/2014 11:03:10 AM
CreationTimeUtc : 7/28/2014 3:03:10 PM
LastAccessTime : 7/28/2014 11:03:10 AM
LastAccessTimeUtc : 7/28/2014 3:03:10 PM
LastWriteTime : 7/28/2014 11:03:10 AM
LastWriteTimeUtc : 7/28/2014 3:03:10 PM
Attributes : Directory
BaseName : temp
Mode : d----
The output I am expecting is:
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 7/28/2014 11:03 AM temp
If I pipe the output of LoadWithPartialName to Out-Null, then I do get the expected output. I would like to understand what is happening here so I can anticipate these discrepancies in the future.
I think I figured this out.
In the original case with the LoadWithPartialName, the output of the script is an array of PSObject since Powershell sends any unhandled object to the pipeline, and the items are of mixed types (0 = AssemblyInfo from Load; 1 = DirectoryInfo from new-item).
If you redirect the LoadWithPartialName to [void] or even save the output in a variable, the output of the script is a single DirectoryInfo object.
PSObject gets formatted differently than DirectoryInfo