알쓸신잡 Powershell 스크립트 모음6
[Explanation]
Get-ChildItem에서 -Recurse parameter 사용 유무에 따른 결과값의 차이는 -Recurse를 사용하면 지정 경로(디렉토리)의 하위 정보까지 조회 가능하다.
#Recurse 사용하지 않을 경우의 결과값
PS C:\Users\administrator> Get-ChildItem -path "C:\Users\administrator\Downloads"
디렉터리: C:\Users\administrator\Downloads
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2017-12-20 오후 1:15 부엉이
-a--- 2017-12-12 오전 8:42 1491 launch (1).ica
-a--- 2017-12-18 오전 8:38 1490 launch (2).ica
-a--- 2017-12-18 오전 8:37 1491 launch.ica
-a--- 2017-12-06 오전 10:24 1100979 pg38280-images.mobi
-a--- 2017-12-06 오전 10:24 1922397 pg40196-images.mobi
-a--- 2017-12-06 오전 10:24 1653084 pg56006-images.mobi
-a--- 2017-12-14 오후 2:11 10806438 secrets-of-powershell-remoting.pdf
-a--- 2017-12-06 오전 10:14 662033 The Art Of Writing & Speaking The English Language.mobi
#Recurse 사용할 경우의 결과값PS C:\Users\administrator> Get-ChildItem -path "C:\Users\administrator\Downloads" -Recurse
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2017-12-20 오후 1:15 부엉이
-a--- 2017-12-12 오전 8:42 1491 launch (1).ica
-a--- 2017-12-18 오전 8:38 1490 launch (2).ica
-a--- 2017-12-18 오전 8:37 1491 launch.ica
-a--- 2017-12-19 오전 11:31 136192 LG하우시스 VM정보_20171219.xls
-a--- 2017-12-06 오전 10:24 1100979 pg38280-images.mobi
-a--- 2017-12-06 오전 10:24 1922397 pg40196-images.mobi
-a--- 2017-12-06 오전 10:24 1653084 pg56006-images.mobi
-a--- 2017-12-14 오후 2:11 10806438 secrets-of-powershell-remoting.pdf
-a--- 2017-12-06 오전 10:14 662033 The Art Of Writing & Speaking The English Language.mobi
디렉터리: C:\Users\administrator\Downloads\부엉이
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2017-12-20 오후 1:15 해오라기
#특정 파일명이 포함된 파일만 조회할 경우
디렉터리: C:\Users\administrator\Downloads
PS C:\Users\administrator> $Directory = "C:\Users\administrator\Downloads"
Get-ChildItem -path $Directory -Recurse -Include *.ica
디렉터리: C:\Users\administrator\Downloads
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2017-12-12 오전 8:42 1491 launch (1).ica
-a--- 2017-12-18 오전 8:38 1490 launch (2).ica
-a--- 2017-12-18 오전 8:37 1491 launch.ica
#특정 파일 확장자가 포함된 파일을 경로와 이름으로 묶어서 조회할 경우
PS C:\Users\administrator> $Path = "C:\Users\administrator\Downloads"
Get-Childitem $Path -Recurse | where {$_.Extension -Match "ica"}`
| ft -group {$_.Path} Directory, Name -autosize
:
Directory Name
--------- ----
C:\Users\iyamus\Downloads launch (1).ica
C:\Users\iyamus\Downloads launch (2).ica
C:\Users\iyamus\Downloads launch.ica
# 특정경로의 소속정보를 확인하는 'Get-Childitem'과 특정파일의 속성정보를 확인하는 'Get-member'PS C:\Users\administrator> Get-ChildItem 'C:\Users\administrator\Downloads\새 텍스트 문서.txt' | get-member
TypeName: System.IO.FileInfo
Name MemberType Definition
---- ---------- ----------
Mode CodeProperty System.String Mode{get=Mode;}
AppendText Method System.IO.StreamWriter AppendText()
CopyTo Method System.IO.FileInfo CopyTo(string destFileName), System.IO.FileInfo CopyTo(string destFileName, bool overwrite)
Create Method System.IO.FileStream Create()
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
CreateText Method System.IO.StreamWriter CreateText()
Decrypt Method System.Void Decrypt()
Delete Method System.Void Delete()
Encrypt Method System.Void Encrypt()
Equals Method bool Equals(System.Object obj)
GetAccessControl Method System.Security.AccessControl.FileSecurity GetAccessControl(), System.Security.AccessControl.FileSecurity GetAccessControl(System.Security.AccessControl.AccessControlSections includeSections)
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetObjectData Method System.Void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
GetType Method type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
MoveTo Method System.Void MoveTo(string destFileName)
Open Method System.IO.FileStream Open(System.IO.FileMode mode), System.IO.FileStream Open(System.IO.FileMode mode, System.IO.FileAccess access), System.IO.FileStream Open(System.IO.FileMode mode, System.IO.FileAccess access, System.IO.F...
OpenRead Method System.IO.FileStream OpenRead()
OpenText Method System.IO.StreamReader OpenText()
OpenWrite Method System.IO.FileStream OpenWrite()
Refresh Method System.Void Refresh()
Replace Method System.IO.FileInfo Replace(string destinationFileName, string destinationBackupFileName), System.IO.FileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors)
SetAccessControl Method System.Void SetAccessControl(System.Security.AccessControl.FileSecurity fileSecurity)
ToString Method string ToString()
PSChildName NoteProperty System.String PSChildName=새 텍스트 문서.txt
PSDrive NoteProperty System.Management.Automation.PSDriveInfo PSDrive=C
PSIsContainer NoteProperty System.Boolean PSIsContainer=False
PSParentPath NoteProperty System.String PSParentPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\iyamus\Downloads
PSPath NoteProperty System.String PSPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\iyamus\Downloads\새 텍스트 문서.txt
PSProvider NoteProperty System.Management.Automation.ProviderInfo PSProvider=Microsoft.PowerShell.Core\FileSystem
Attributes Property System.IO.FileAttributes Attributes {get;set;}
CreationTime Property System.DateTime CreationTime {get;set;}
CreationTimeUtc Property System.DateTime CreationTimeUtc {get;set;}
Directory Property System.IO.DirectoryInfo Directory {get;}
DirectoryName Property System.String DirectoryName {get;}
Exists Property System.Boolean Exists {get;}
Extension Property System.String Extension {get;}
FullName Property System.String FullName {get;}
IsReadOnly Property System.Boolean IsReadOnly {get;set;}
LastAccessTime Property System.DateTime LastAccessTime {get;set;}
LastAccessTimeUtc Property System.DateTime LastAccessTimeUtc {get;set;}
LastWriteTime Property System.DateTime LastWriteTime {get;set;}
LastWriteTimeUtc Property System.DateTime LastWriteTimeUtc {get;set;}
Length Property System.Int64 Length {get;}
Name Property System.String Name {get;}
BaseName ScriptProperty System.Object BaseName {get=if ($this.Extension.Length -gt 0){$this.Name.Remove($this.Name.Length - $this.Extension.Length)}else{$this.Name};}
VersionInfo ScriptProperty System.Object VersionInfo {get=[System.Diagnostics.FileVersionInfo]::GetVersionInfo($this.FullName);}
LastWriteTime : 2017-12-20 오후 1:41:17
Length : 0
Name : 새 텍스트 문서.txt
#특정파일의 속성정보를 확인하는 'Get-member'을 활용하여 Filtering 가능하다PS C:\Users\administrator> Get-ChildItem -Path $path -Recurse | ?{$_.Extension -Match "txt"}
디렉터리: C:\Users\administrator\Downloads
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2017-12-20 오후 1:41 0 새 텍스트 문서.txt
댓글이나 의견은 언제든지 환영합니다.
Your Comments are Always Welcomed!
0 comments:
Post a Comment