我有 Windows 10(版本 1909)。当我发出以下 CMD 时,它可以正常工作,FILESIZE 列正确。
Win 10 PS版本:
Major Minor Build Revision
----- ----- ----- --------
5 1 18362 752
PS C:\backup> Get-ChildItem -path c:\temp\*.* -Filter *.ps1 | select name,FileSize,lastwritetime,CreationTime | sort LastWriteTime -descending
Name FileSize LastWriteTime CreationTime
---- -------- ------------- ------------
test.ps1 1.82 KB 02/06/2019 9:20:47 AM 10/02/2018 8:52:42 AM
test2.ps1 899 B 02/06/2019 8:17:38 AM 02/06/2019 8:17:37 AM
getlastlogon with server name also.ps1 1.50 KB 02/06/2019 8:13:01 AM 02/06/2019 8:13:01 AM
MyTypes.ps1xml 1.01 KB 12/11/2018 4:34:10 PM 12/11/2018 4:34:01 PM
Get-LockedOutLocation.ps1 4.70 KB 10/02/2018 9:07:36 AM 10/02/2018 9:07:36 AM
但是如果我在 Windows 2008 服务器上发出此命令,FILESIZE 列始终为空。
Major Minor Build Revision
----- ----- ----- --------
5 1 14409 1005
PS C:\Users\barcode> Get-ChildItem -path c:\temp\*.* | select name,FileSize,lastwritetime,CreationTime | sort LastWrite
Time -descending
Name FileSize LastWriteTime CreationTime
---- -------- ------------- ------------
PS5-Win7AndW2K8R2-KB3191566-x64.zip 4/21/2020 11:12:22 AM 4/21/2020 11:43:47 AM
barcode_new_Srv.bmp 6/28/2018 8:40:12 AM 6/28/2018 8:33:25 AM
Install-WMF5.1.ps1 1/18/2017 3:25:24 PM 4/21/2020 11:43:58 AM
Win7AndW2K8R2-KB3191566-x64.msu 1/13/2017 10:07:44 AM 4/21/2020 11:43:58 AM
我也尝试在 W2008 上安装 Ps7,但 FILESIZE 列仍然为空。
答案1
您想要的属性被称为Length
(不是FileSize
):
Get-ChildItem -Path c:\temp\*.* -Filter *.ps1 | select Mame,Length,LastWriteTime,CreationTime | sort LastWriteTime -Descending
如果要查看对象集合具有哪些属性,请通过管道传输至Get-Member
:
PS C:\> Get-ChildItem -Path c:\temp\*.* -Filter *.ps1 |Get-Member
TypeName: System.IO.FileInfo
Name MemberType Definition
---- ---------- ----------
LinkType CodeProperty System.String LinkType{get=GetLinkType;}
Mode CodeProperty System.String Mode{get=Mode;}
Target CodeProperty System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=4.0.0.0, Cu...
AppendText Method System.IO.StreamWriter AppendText()
CopyTo Method System.IO.FileInfo CopyTo(string destFileName), System.IO.FileInfo CopyTo(string destF...
Create Method System.IO.FileStream Create()
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
CreateText Method System.IO.StreamWriter CreateText()
Decrypt Method void Decrypt()
Delete Method void Delete()
Encrypt Method void Encrypt()
Equals Method bool Equals(System.Object obj)
GetAccessControl Method System.Security.AccessControl.FileSecurity GetAccessControl(), System.Security.AccessC...
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetObjectData Method void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime...
GetType Method type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
MoveTo Method void MoveTo(string destFileName)
Open Method System.IO.FileStream Open(System.IO.FileMode mode), System.IO.FileStream Open(System.I...
OpenRead Method System.IO.FileStream OpenRead()
OpenText Method System.IO.StreamReader OpenText()
OpenWrite Method System.IO.FileStream OpenWrite()
Refresh Method void Refresh()
Replace Method System.IO.FileInfo Replace(string destinationFileName, string destinationBackupFileNam...
SetAccessControl Method void SetAccessControl(System.Security.AccessControl.FileSecurity fileSecurity)
ToString Method string ToString()
PSChildName NoteProperty string PSChildName=f.ps1
PSDrive NoteProperty PSDriveInfo PSDrive=C
PSIsContainer NoteProperty bool PSIsContainer=False
PSParentPath NoteProperty string PSParentPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\mjessen
PSPath NoteProperty string PSPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\mjessen\f.ps1
PSProvider NoteProperty ProviderInfo PSProvider=Microsoft.PowerShell.Core\FileSystem
Attributes Property System.IO.FileAttributes Attributes {get;set;}
CreationTime Property datetime CreationTime {get;set;}
CreationTimeUtc Property datetime CreationTimeUtc {get;set;}
Directory Property System.IO.DirectoryInfo Directory {get;}
DirectoryName Property string DirectoryName {get;}
Exists Property bool Exists {get;}
Extension Property string Extension {get;}
FullName Property string FullName {get;}
IsReadOnly Property bool IsReadOnly {get;set;}
LastAccessTime Property datetime LastAccessTime {get;set;}
LastAccessTimeUtc Property datetime LastAccessTimeUtc {get;set;}
LastWriteTime Property datetime LastWriteTime {get;set;}
LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;}
Length Property long Length {get;}
Name Property string Name {get;}
BaseName ScriptProperty System.Object BaseName {get=if ($this.Extension.Length -gt 0){$this.Name.Remove($this....
VersionInfo ScriptProperty System.Object VersionInfo {get=[System.Diagnostics.FileVersionInfo]::GetVersionInfo($t...