鷲ノ巣

C# とか PowerShell とか。当ブログの記事は(特に公開直後は)頻繁に改定される場合があることをご了承ください。

Get-Content の罠

本記事は PowerShell Advent Calendar 2017 の 20 日目です。
1 分で読めます。
qiita.com

何が罠だって?

こうするじゃろ?

echo foo > test.txt
echo bar >> test.txt

で、こうするじゃろ?

$content = Get-Content .\test.txt

こうじゃろ?

PS D:\> $content
foo
bar

からの、こうじゃろ?

$content | ConvertTo-Json

ふぁっ!?

[
    {
        "value": "foo",
        "PSPath": "D:\\test.txt",
        "PSParentPath": "D:\\",
        "PSChildName": "test.txt",
        "PSDrive": {
            "CurrentLocation": "",
            "Name": "D",
            "Provider": "Microsoft.PowerShell.Core\\FileSystem",
            "Root": "D:\\",
            "Description": "",
            "MaximumSize": null,
            "Credential": "System.Management.Automation.PSCredential",
            "DisplayRoot": null
        },
        "PSProvider": {
            "ImplementingType": "Microsoft.PowerShell.Commands.FileSystemProvider",
            "HelpFile": "System.Management.Automation.dll-Help.xml",
            "Name": "FileSystem",
            "PSSnapIn": "Microsoft.PowerShell.Core",
            "ModuleName": "Microsoft.PowerShell.Core",
            "Module": null,
            "Description": "",
            "Capabilities": 52,
            "Home": "C:\\Users\\aetos",
            "Drives": "C D"
        },
        "ReadCount": 1
    },
    {
        "value": "bar",
        "PSPath": "D:\\test.txt",
        "PSParentPath": "D:\\",
        "PSChildName": "test.txt",
        "PSDrive": {
            "CurrentLocation": "",
            "Name": "D",
            "Provider": "Microsoft.PowerShell.Core\\FileSystem",
            "Root": "D:\\",
            "Description": "",
            "MaximumSize": null,
            "Credential": "System.Management.Automation.PSCredential",
            "DisplayRoot": null
        },
        "PSProvider": {
            "ImplementingType": "Microsoft.PowerShell.Commands.FileSystemProvider",
            "HelpFile": "System.Management.Automation.dll-Help.xml",
            "Name": "FileSystem",
            "PSSnapIn": "Microsoft.PowerShell.Core",
            "ModuleName": "Microsoft.PowerShell.Core",
            "Module": null,
            "Description": "",
            "Capabilities": 52,
            "Home": "C:\\Users\\aetos",
            "Drives": "C D"
        },
        "ReadCount": 2
    }
]

どうするの?

こう。

$content = [string[]] Get-Content .\test.txt
$content | ConvertTo-Json
[
    "foo",
    "bar"
]

よし。

テキスト ファイルに何かのリストを書いておいて、それを読み込んで JSON を組み立てて Web API に投げるようなことをしている場合は注意です。

ちなみに

キャストせずに -Raw オプションをつけたらもっとすごいことになった。

$content = Get-Content .\test.txt -Raw
$content | ConvertTo-Json
{
    "value": "foo\r\nbar\r\n",
    "PSPath": "D:\\test.txt",
    "PSParentPath": "D:\\",
    "PSChildName": "test.txt",
    "PSDrive": {
        "CurrentLocation": "",
        "Name": "D",
        "Provider": {
            "ImplementingType": "Microsoft.PowerShell.Commands.FileSystemProvider",
            "HelpFile": "System.Management.Automation.dll-Help.xml",
            "Name": "FileSystem",
            "PSSnapIn": "Microsoft.PowerShell.Core",
            "ModuleName": "Microsoft.PowerShell.Core",
            "Module": null,
            "Description": "",
            "Capabilities": 52,
            "Home": "C:\\Users\\aetos",
            "Drives": "C D"
        },
        "Root": "D:\\",
        "Description": "",
        "MaximumSize": null,
        "Credential": {
            "UserName": null,
            "Password": null
        },
        "DisplayRoot": null
    },
    "PSProvider": {
        "ImplementingType": {
            "Module": "System.Management.Automation.dll",
            "Assembly": "System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
            "TypeHandle": "System.RuntimeTypeHandle",
            "DeclaringMethod": null,
            "BaseType": "System.Management.Automation.Provider.NavigationCmdletProvider",
            "UnderlyingSystemType": "Microsoft.PowerShell.Commands.FileSystemProvider",
            "FullName": "Microsoft.PowerShell.Commands.FileSystemProvider",
            "AssemblyQualifiedName": "Microsoft.PowerShell.Commands.FileSystemProvider, System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
            "Namespace": "Microsoft.PowerShell.Commands",
            "GUID": "b4755d19-b6a7-38dc-ae06-4167f801062f",
            "IsEnum": false,
            "GenericParameterAttributes": null,
            "IsSecurityCritical": true,
            "IsSecuritySafeCritical": false,
            "IsSecurityTransparent": false,
            "IsGenericTypeDefinition": false,
            "IsGenericParameter": false,
            "GenericParameterPosition": null,
            "IsGenericType": false,
            "IsConstructedGenericType": false,
            "ContainsGenericParameters": false,
            "StructLayoutAttribute": "System.Runtime.InteropServices.StructLayoutAttribute",
            "Name": "FileSystemProvider",
            "MemberType": 32,
            "DeclaringType": null,
            "ReflectedType": null,
            "MetadataToken": 33554727,
            "GenericTypeParameters": "",
            "DeclaredConstructors": "Void .ctor() Void .cctor()",
            "DeclaredEvents": "",
            "DeclaredFields": "System.Collections.ObjectModel.Collection`1[System.Management.Automation.WildcardPattern] excludeMatcher System.Management.Automation.PSTraceSource tracer Int32 FILETRANSFERSIZE System.String ProviderName",
            "DeclaredMembers": "System.String Mode(System.Management.Automation.PSObject) System.Object GetChildItemsDynamicParameters(System.String, Boolean) System.String NormalizePath(System.String) System.IO.FileSystemInfo GetFileSystemInfo(System.String, Boolean ByRef) Boolean IsFilterSet() System.Object GetChildNamesDynamicParameters(System.String) System.Object CopyItemDynamicParameters(System.String, System.String, Boolean) System.String GetHelpMaml(System.String, System.String) System.Management.Automation.ProviderInfo Start(System.Management.Automation.ProviderInfo) System.Management.Automation.PSDriveInfo NewDrive(System.Management.Automation.PSDriveInfo) Void MapNetworkDrive(System.Management.Automation.PSDriveInfo) Boolean IsNetworkMappedDrive(System.Management.Automation.PSDriveInfo) System.Management.Automation.PSDriveInfo RemoveDrive(System.Management.Automation.PSDriveInfo) Boolean IsSupportedDriveForPersistence(System.Management.Automation.PSDriveInfo) System.String GetUNCForNetworkDrive(System.String) System.String GetSubstitutedPathForNetworkDosDevice(System.String) System.String GetRootPathForNetworkDriveOrDosDevice(System.IO.DriveInfo) System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSDriveInfo] InitializeDefaultDrives() System.Object GetItemDynamicParameters(System.String) Boolean IsValidPath(System.String) Void GetItem(System.String) System.IO.FileSystemInfo GetFileSystemItem(System.String, Boolean ByRef, Boolean) Void InvokeDefaultAction(System.String) Void GetChildItems(System.String, Boolean, UInt32) Void GetChildNames(System.String, System.Management.Automation.ReturnContainers) Boolean ConvertPath(System.String, System.String, System.String ByRef, System.String ByRef) Void GetPathItems(System.String, Boolean, UInt32, Boolean, System.Management.Automation.ReturnContainers) Void Dir(System.IO.DirectoryInfo, Boolean, UInt32, Boolean, System.Management.Automation.ReturnContainers) System.Management.Automation.FlagsExpression`1[System.IO.FileAttributes] FormatAttributeSwitchParamters() Void RenameItem(System.String, System.String) Void NewItem(System.String, System.String, System.Object) Boolean CheckItemExists(System.String, Boolean ByRef) ItemType GetItemType(System.String) Void CreateDirectory(System.String, Boolean) Boolean CreateIntermediateDirectories(System.String) Void RemoveItem(System.String, Boolean) System.Object RemoveItemDynamicParameters(System.String, Boolean) Void RemoveDirectoryInfoItem(System.IO.DirectoryInfo, Boolean, Boolean, Boolean) Void RemoveFileInfoItem(System.IO.FileInfo, Boolean) Void RemoveFileSystemItem(System.IO.FileSystemInfo, Boolean) Boolean ItemExists(System.String) Boolean ItemExists(System.String, System.Management.Automation.ErrorRecord ByRef) System.Object ItemExistsDynamicParameters(System.String) Boolean HasChildItems(System.String) Boolean DirectoryInfoHasChildItems(System.IO.DirectoryInfo) Void CopyItem(System.String, System.String, Boolean) Void CopyItemFromRemoteSession(System.String, System.String, Boolean, Boolean, System.Management.Automation.Runspaces.PSSession) Void CopyItemLocalOrToSession(System.String, System.String, Boolean, Boolean, System.Management.Automation.PowerShell) Void CopyDirectoryInfoItem(System.IO.DirectoryInfo, System.String, Boolean, Boolean, System.Management.Automation.PowerShell) Void CopyFileInfoItem(System.IO.FileInfo, System.String, Boolean, System.Management.Automation.PowerShell) Void CopyDirectoryFromRemoteSession(System.String, System.String, System.String, Boolean, Boolean, System.Management.Automation.PowerShell) System.Collections.ArrayList GetRemoteSourceAlternateStreams(System.Management.Automation.PowerShell, System.String) Void InitilizeFunctionPSCopyFileFromRemoteSession(System.Management.Automation.PowerShell) Void RemoveFunctionsPSCopyFileFromRemoteSession(System.Management.Automation.PowerShell) Boolean ValidRemoteSessionForScripting(System.Management.Automation.Runspaces.Runspace) System.Collections.Hashtable GetRemoteFileMetadata(System.String, System.Management.Automation.PowerShell) Void SetFileMetadata(System.String, System.IO.FileInfo, System.Management.Automation.PowerShell) Void CopyFileFromRemoteSession(System.String, System.String, System.String, Boolean, System.Management.Automation.PowerShell, Int64) Boolean PerformCopyFileFromRemoteSession(System.String, System.IO.FileInfo, System.String, Boolean, System.Management.Automation.PowerShell, Int64, Boolean, System.String) Void InitilizeFunctionsPSCopyFileToRemoteSession(System.Management.Automation.PowerShell) Void RemoveFunctionPSCopyFileToRemoteSession(System.Management.Automation.PowerShell) Boolean RemoteTargetSupportsAlternateStreams(System.Management.Automation.PowerShell, System.String) System.String MakeRemotePath(System.Management.Automation.PowerShell, System.String, System.String) Boolean RemoteDirectoryExist(System.Management.Automation.PowerShell, System.String) Boolean CopyFileStreamToRemoteSession(System.IO.FileInfo, System.String, System.Management.Automation.PowerShell, Boolean, System.String) System.Collections.Hashtable GetFileMetadata(System.IO.FileInfo) Void SetRemoteFileMetadata(System.IO.FileInfo, System.String, System.Management.Automation.PowerShell) Boolean PerformCopyFileToRemoteSession(System.IO.FileInfo, System.String, System.Management.Automation.PowerShell) Boolean RemoteDestinationPathIsFile(System.String, System.Management.Automation.PowerShell) System.String CreateDirectoryOnRemoteSession(System.String, Boolean, System.Management.Automation.PowerShell) Boolean PathIsReservedDeviceName(System.String, System.String) System.String GetParentPath(System.String, System.String) Boolean IsAbsolutePath(System.String) Boolean IsUNCPath(System.String) Boolean IsUNCRoot(System.String) Boolean IsPathRoot(System.String) System.String NormalizeRelativePath(System.String, System.String) System.String NormalizeRelativePathHelper(System.String, System.String) System.String RemoveRelativeTokens(System.String) System.String GetCommonBase(System.String, System.String) System.Collections.Generic.Stack`1[System.String] TokenizePathToStack(System.String, System.String) System.Collections.Generic.Stack`1[System.String] NormalizeThePath(System.String, System.Collections.Generic.Stack`1[System.String]) System.String CreateNormalizedRelativePathFromStack(System.Collections.Generic.Stack`1[System.String]) System.String GetChildName(System.String) System.String EnsureDriveIsRooted(System.String) Boolean IsItemContainer(System.String) Void MoveItem(System.String, System.String) Void MoveFileInfoItem(System.IO.FileInfo, System.String, Boolean, Boolean) Void MoveDirectoryInfoItem(System.IO.DirectoryInfo, System.String, Boolean) Void CopyAndDelete(System.IO.DirectoryInfo, System.String, Boolean) Boolean IsSameVolume(System.String, System.String) Void GetProperty(System.String, System.Collections.ObjectModel.Collection`1[System.String]) System.Object GetPropertyDynamicParameters(System.String, System.Collections.ObjectModel.Collection`1[System.String]) Void SetProperty(System.String, System.Management.Automation.PSObject) System.Object SetPropertyDynamicParameters(System.String, System.Management.Automation.PSObject) Void ClearProperty(System.String, System.Collections.ObjectModel.Collection`1[System.String]) System.Object ClearPropertyDynamicParameters(System.String, System.Collections.ObjectModel.Collection`1[System.String]) System.Management.Automation.Provider.IContentReader GetContentReader(System.String) System.Object GetContentReaderDynamicParameters(System.String) System.Management.Automation.Provider.IContentWriter GetContentWriter(System.String) System.Object GetContentWriterDynamicParameters(System.String) Void ClearContent(System.String) System.Object ClearContentDynamicParameters(System.String) Int32 SafeGetFileAttributes(System.String) Void ValidateParameters(Boolean) Void GetSecurityDescriptor(System.String, System.Security.AccessControl.AccessControlSections) Void SetSecurityDescriptor(System.String, System.Security.AccessControl.ObjectSecurity) Void SetSecurityDescriptor(System.String, System.Security.AccessControl.ObjectSecurity, System.Security.AccessControl.AccessControlSections) System.Security.AccessControl.ObjectSecurity NewSecurityDescriptorFromPath(System.String, System.Security.AccessControl.AccessControlSections) System.Security.AccessControl.ObjectSecurity NewSecurityDescriptorOfType(System.String, System.Security.AccessControl.AccessControlSections) System.Security.AccessControl.ObjectSecurity NewSecurityDescriptor(ItemType) System.Management.Automation.ErrorRecord CreateErrorRecord(System.String, System.String) Void .ctor() Void .cctor() System.Collections.ObjectModel.Collection`1[System.Management.Automation.WildcardPattern] excludeMatcher System.Management.Automation.PSTraceSource tracer Int32 FILETRANSFERSIZE System.String ProviderName Microsoft.PowerShell.Commands.FileSystemProvider+ItemType Microsoft.PowerShell.Commands.FileSystemProvider+NativeMethods Microsoft.PowerShell.Commands.FileSystemProvider+NetResource",
            "DeclaredMethods": "System.String Mode(System.Management.Automation.PSObject) System.Object GetChildItemsDynamicParameters(System.String, Boolean) System.String NormalizePath(System.String) System.IO.FileSystemInfo GetFileSystemInfo(System.String, Boolean ByRef) Boolean IsFilterSet() System.Object GetChildNamesDynamicParameters(System.String) System.Object CopyItemDynamicParameters(System.String, System.String, Boolean) System.String GetHelpMaml(System.String, System.String) System.Management.Automation.ProviderInfo Start(System.Management.Automation.ProviderInfo) System.Management.Automation.PSDriveInfo NewDrive(System.Management.Automation.PSDriveInfo) Void MapNetworkDrive(System.Management.Automation.PSDriveInfo) Boolean IsNetworkMappedDrive(System.Management.Automation.PSDriveInfo) System.Management.Automation.PSDriveInfo RemoveDrive(System.Management.Automation.PSDriveInfo) Boolean IsSupportedDriveForPersistence(System.Management.Automation.PSDriveInfo) System.String GetUNCForNetworkDrive(System.String) System.String GetSubstitutedPathForNetworkDosDevice(System.String) System.String GetRootPathForNetworkDriveOrDosDevice(System.IO.DriveInfo) System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSDriveInfo] InitializeDefaultDrives() System.Object GetItemDynamicParameters(System.String) Boolean IsValidPath(System.String) Void GetItem(System.String) System.IO.FileSystemInfo GetFileSystemItem(System.String, Boolean ByRef, Boolean) Void InvokeDefaultAction(System.String) Void GetChildItems(System.String, Boolean, UInt32) Void GetChildNames(System.String, System.Management.Automation.ReturnContainers) Boolean ConvertPath(System.String, System.String, System.String ByRef, System.String ByRef) Void GetPathItems(System.String, Boolean, UInt32, Boolean, System.Management.Automation.ReturnContainers) Void Dir(System.IO.DirectoryInfo, Boolean, UInt32, Boolean, System.Management.Automation.ReturnContainers) System.Management.Automation.FlagsExpression`1[System.IO.FileAttributes] FormatAttributeSwitchParamters() Void RenameItem(System.String, System.String) Void NewItem(System.String, System.String, System.Object) Boolean CheckItemExists(System.String, Boolean ByRef) ItemType GetItemType(System.String) Void CreateDirectory(System.String, Boolean) Boolean CreateIntermediateDirectories(System.String) Void RemoveItem(System.String, Boolean) System.Object RemoveItemDynamicParameters(System.String, Boolean) Void RemoveDirectoryInfoItem(System.IO.DirectoryInfo, Boolean, Boolean, Boolean) Void RemoveFileInfoItem(System.IO.FileInfo, Boolean) Void RemoveFileSystemItem(System.IO.FileSystemInfo, Boolean) Boolean ItemExists(System.String) Boolean ItemExists(System.String, System.Management.Automation.ErrorRecord ByRef) System.Object ItemExistsDynamicParameters(System.String) Boolean HasChildItems(System.String) Boolean DirectoryInfoHasChildItems(System.IO.DirectoryInfo) Void CopyItem(System.String, System.String, Boolean) Void CopyItemFromRemoteSession(System.String, System.String, Boolean, Boolean, System.Management.Automation.Runspaces.PSSession) Void CopyItemLocalOrToSession(System.String, System.String, Boolean, Boolean, System.Management.Automation.PowerShell) Void CopyDirectoryInfoItem(System.IO.DirectoryInfo, System.String, Boolean, Boolean, System.Management.Automation.PowerShell) Void CopyFileInfoItem(System.IO.FileInfo, System.String, Boolean, System.Management.Automation.PowerShell) Void CopyDirectoryFromRemoteSession(System.String, System.String, System.String, Boolean, Boolean, System.Management.Automation.PowerShell) System.Collections.ArrayList GetRemoteSourceAlternateStreams(System.Management.Automation.PowerShell, System.String) Void InitilizeFunctionPSCopyFileFromRemoteSession(System.Management.Automation.PowerShell) Void RemoveFunctionsPSCopyFileFromRemoteSession(System.Management.Automation.PowerShell) Boolean ValidRemoteSessionForScripting(System.Management.Automation.Runspaces.Runspace) System.Collections.Hashtable GetRemoteFileMetadata(System.String, System.Management.Automation.PowerShell) Void SetFileMetadata(System.String, System.IO.FileInfo, System.Management.Automation.PowerShell) Void CopyFileFromRemoteSession(System.String, System.String, System.String, Boolean, System.Management.Automation.PowerShell, Int64) Boolean PerformCopyFileFromRemoteSession(System.String, System.IO.FileInfo, System.String, Boolean, System.Management.Automation.PowerShell, Int64, Boolean, System.String) Void InitilizeFunctionsPSCopyFileToRemoteSession(System.Management.Automation.PowerShell) Void RemoveFunctionPSCopyFileToRemoteSession(System.Management.Automation.PowerShell) Boolean RemoteTargetSupportsAlternateStreams(System.Management.Automation.PowerShell, System.String) System.String MakeRemotePath(System.Management.Automation.PowerShell, System.String, System.String) Boolean RemoteDirectoryExist(System.Management.Automation.PowerShell, System.String) Boolean CopyFileStreamToRemoteSession(System.IO.FileInfo, System.String, System.Management.Automation.PowerShell, Boolean, System.String) System.Collections.Hashtable GetFileMetadata(System.IO.FileInfo) Void SetRemoteFileMetadata(System.IO.FileInfo, System.String, System.Management.Automation.PowerShell) Boolean PerformCopyFileToRemoteSession(System.IO.FileInfo, System.String, System.Management.Automation.PowerShell) Boolean RemoteDestinationPathIsFile(System.String, System.Management.Automation.PowerShell) System.String CreateDirectoryOnRemoteSession(System.String, Boolean, System.Management.Automation.PowerShell) Boolean PathIsReservedDeviceName(System.String, System.String) System.String GetParentPath(System.String, System.String) Boolean IsAbsolutePath(System.String) Boolean IsUNCPath(System.String) Boolean IsUNCRoot(System.String) Boolean IsPathRoot(System.String) System.String NormalizeRelativePath(System.String, System.String) System.String NormalizeRelativePathHelper(System.String, System.String) System.String RemoveRelativeTokens(System.String) System.String GetCommonBase(System.String, System.String) System.Collections.Generic.Stack`1[System.String] TokenizePathToStack(System.String, System.String) System.Collections.Generic.Stack`1[System.String] NormalizeThePath(System.String, System.Collections.Generic.Stack`1[System.String]) System.String CreateNormalizedRelativePathFromStack(System.Collections.Generic.Stack`1[System.String]) System.String GetChildName(System.String) System.String EnsureDriveIsRooted(System.String) Boolean IsItemContainer(System.String) Void MoveItem(System.String, System.String) Void MoveFileInfoItem(System.IO.FileInfo, System.String, Boolean, Boolean) Void MoveDirectoryInfoItem(System.IO.DirectoryInfo, System.String, Boolean) Void CopyAndDelete(System.IO.DirectoryInfo, System.String, Boolean) Boolean IsSameVolume(System.String, System.String) Void GetProperty(System.String, System.Collections.ObjectModel.Collection`1[System.String]) System.Object GetPropertyDynamicParameters(System.String, System.Collections.ObjectModel.Collection`1[System.String]) Void SetProperty(System.String, System.Management.Automation.PSObject) System.Object SetPropertyDynamicParameters(System.String, System.Management.Automation.PSObject) Void ClearProperty(System.String, System.Collections.ObjectModel.Collection`1[System.String]) System.Object ClearPropertyDynamicParameters(System.String, System.Collections.ObjectModel.Collection`1[System.String]) System.Management.Automation.Provider.IContentReader GetContentReader(System.String) System.Object GetContentReaderDynamicParameters(System.String) System.Management.Automation.Provider.IContentWriter GetContentWriter(System.String) System.Object GetContentWriterDynamicParameters(System.String) Void ClearContent(System.String) System.Object ClearContentDynamicParameters(System.String) Int32 SafeGetFileAttributes(System.String) Void ValidateParameters(Boolean) Void GetSecurityDescriptor(System.String, System.Security.AccessControl.AccessControlSections) Void SetSecurityDescriptor(System.String, System.Security.AccessControl.ObjectSecurity) Void SetSecurityDescriptor(System.String, System.Security.AccessControl.ObjectSecurity, System.Security.AccessControl.AccessControlSections) System.Security.AccessControl.ObjectSecurity NewSecurityDescriptorFromPath(System.String, System.Security.AccessControl.AccessControlSections) System.Security.AccessControl.ObjectSecurity NewSecurityDescriptorOfType(System.String, System.Security.AccessControl.AccessControlSections) System.Security.AccessControl.ObjectSecurity NewSecurityDescriptor(ItemType) System.Management.Automation.ErrorRecord CreateErrorRecord(System.String, System.String)",
            "DeclaredNestedTypes": "Microsoft.PowerShell.Commands.FileSystemProvider+ItemType Microsoft.PowerShell.Commands.FileSystemProvider+NativeMethods Microsoft.PowerShell.Commands.FileSystemProvider+NetResource",
            "DeclaredProperties": "",
            "ImplementedInterfaces": "System.Management.Automation.IResourceSupplier System.Management.Automation.Provider.IContentCmdletProvider System.Management.Automation.Provider.IPropertyCmdletProvider System.Management.Automation.Provider.ISecurityDescriptorCmdletProvider System.Management.Automation.Provider.ICmdletProviderSupportsHelp",
            "TypeInitializer": "Void .cctor()",
            "IsNested": false,
            "Attributes": 1048833,
            "IsVisible": true,
            "IsNotPublic": false,
            "IsPublic": true,
            "IsNestedPublic": false,
            "IsNestedPrivate": false,
            "IsNestedFamily": false,
            "IsNestedAssembly": false,
            "IsNestedFamANDAssem": false,
            "IsNestedFamORAssem": false,
            "IsAutoLayout": true,
            "IsLayoutSequential": false,
            "IsExplicitLayout": false,
            "IsClass": true,
            "IsInterface": false,
            "IsValueType": false,
            "IsAbstract": false,
            "IsSealed": true,
            "IsSpecialName": false,
            "IsImport": false,
            "IsSerializable": false,
            "IsAnsiClass": true,
            "IsUnicodeClass": false,
            "IsAutoClass": false,
            "IsArray": false,
            "IsByRef": false,
            "IsPointer": false,
            "IsPrimitive": false,
            "IsCOMObject": false,
            "HasElementType": false,
            "IsContextful": false,
            "IsMarshalByRef": false,
            "GenericTypeArguments": "",
            "CustomAttributes": "[System.Management.Automation.OutputTypeAttribute(new Type[2] { typeof(System.Byte), typeof(System.String) }, ProviderCmdlet = \"Get-Content\")] [System.Management.Automation.OutputTypeAttribute(typeof(System.Security.AccessControl.FileSecurity), ProviderCmdlet = \"Set-Acl\")] [System.Management.Automation.OutputTypeAttribute(new Type[2] { typeof(System.String), typeof(System.Management.Automation.PathInfo) }, ProviderCmdlet = \"Resolve-Path\")] [System.Management.Automation.OutputTypeAttribute(typeof(System.Management.Automation.PathInfo), ProviderCmdlet = \"Push-Location\")] [System.Management.Automation.Provider.CmdletProviderAttribute(\"FileSystem\", (System.Management.Automation.Provider.ProviderCapabilities)52)] [System.Management.Automation.OutputTypeAttribute(typeof(System.IO.FileInfo), ProviderCmdlet = \"Get-Item\")] [System.Management.Automation.OutputTypeAttribute(new Type[2] { typeof(System.IO.FileInfo), typeof(System.IO.DirectoryInfo) }, ProviderCmdlet = \"Get-ChildItem\")] [System.Management.Automation.OutputTypeAttribute(new Type[2] { typeof(System.Security.AccessControl.FileSecurity), typeof(System.Security.AccessControl.DirectorySecurity) }, ProviderCmdlet = \"Get-Acl\")] [System.Management.Automation.OutputTypeAttribute(new Type[4] { typeof(System.Boolean), typeof(System.String), typeof(System.IO.FileInfo), typeof(System.IO.DirectoryInfo) }, ProviderCmdlet = \"Get-Item\")] [System.Management.Automation.OutputTypeAttribute(new Type[5] { typeof(System.Boolean), typeof(System.String), typeof(System.DateTime), typeof(System.IO.FileInfo), typeof(System.IO.DirectoryInfo) }, ProviderCmdlet = \"Get-ItemProperty\")] [System.Management.Automation.OutputTypeAttribute(new Type[2] { typeof(System.String), typeof(System.IO.FileInfo) }, ProviderCmdlet = \"New-Item\")]"
        },
        "HelpFile": "System.Management.Automation.dll-Help.xml",
        "Name": "FileSystem",
        "PSSnapIn": {
            "Name": "Microsoft.PowerShell.Core",
            "IsDefault": true,
            "ApplicationBase": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0",
            "AssemblyName": "System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL",
            "ModuleName": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\System.Management.Automation.dll",
            "PSVersion": "5.1.16299.98",
            "Version": "3.0.0.0",
            "Types": "types.ps1xml typesv3.ps1xml",
            "Formats": "Certificate.format.ps1xml DotNetTypes.format.ps1xml FileSystem.format.ps1xml Help.format.ps1xml HelpV3.format.ps1xml PowerShellCore.format.ps1xml PowerShellTrace.format.ps1xml Registry.format.ps1xml",
            "Description": "この Windows PowerShell スナップインには、Windows PowerShell のコンポーネントを管理するために使用するコマンドレットが含まれています。",
            "Vendor": "Microsoft Corporation",
            "LogPipelineExecutionDetails": false
        },
        "ModuleName": "Microsoft.PowerShell.Core",
        "Module": null,
        "Description": "",
        "Capabilities": 52,
        "Home": "C:\\Users\\aetos",
        "Drives": [
            "C",
            "D"
        ]
    },
    "ReadCount": 1
}

おぉ…

-Raw は結果を配列ではなく単一の文字列として返すオプションであって、余計なプロパティを付加しない生の文字列を返すオプションではありません。
で、配列でなくなった分、プロパティが一階層深いところまでシリアライズされるようになったんですね(ConvertTo-Json は -Depth パラメーターを明示しない限り、2 階層までしかシリアライズしない)。