본문 바로가기

반응형

Windows 10

(18)
PowerShell : TrustedInstaller 권한 때문에 삭제 불가능한 파일 삭제하기 윈도우의 시스템 파일 보호를 위해 TrustedInstaller 권한을 부여받아야만 삭제가 가능한 파일들이 있다. 예를 들어 C:\Windows\SysWOW64\OneDriveSetup.exe 파일의 경우 삭제가 불가능하다. 이 경우 아래 명령어를 통해서 파일의 소유와 권한을 변경하여 삭제 할 수 있다. TakeOwn /f 파일 ICacls 파일 /grant Administrators:f rm 파일 TakeOwn /f "C:\Windows\SysWOW64\OneDriveSetup.exe" ICacls "C:\Windows\SysWOW64\OneDriveSetup.exe" /grant Administrators:f RM "C:\Windows\SysWOW64\OneDriveSetup.exe"
PowerShell : Registry □ PowerShll로 레지스트리 다루기 파워쉘로 레지스트리 생성, 수정, 삭제하기 예제를 위해 아래 순으로 명령어를 사용하면 레지스트리의 키를 생성, 수정, 삭제를 해볼 수 있다. 레지스트리 보기 (Get-ChildItem) # ls 명령어를 이용하며, 앞에 Registry::로 시작하면 된다. (Get-ChildItem의 Alias) ls Registry::HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\ # ls 명령어와 같이 Recurse 옵션 등을 쓸 수 있다. ls Registry::HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\ -Recurse 키 만들기 (New-Item) # 키를 만드는 경우 NI 명령어를 사용한다...
PowerShell : Get-ChildItem (ls), 응용 ls Get-ChildItem ls (Alias) ls ls C:\ 필터 ls -filter *.jpg 다중필터 (Where 적용) ls | Where {$_.extension -in ".mp4", ".avi", ".mkv"} 폴더만 표시 ls -directory ls -dir ls -ad 파일만 표시 ls -file ls -af 숨긴파일만 표시 ls -hidden 파일 전체경로 표시 ls | select fullname ls | % {$_.fullname} 속성으로 찾기 ls -attribute r ls -attr r ls -attr d+r ls -attr d+!r ls -attr !d mode로 찾기 ls | where {$_.mode -in "d-r---"} 파일 개수 확인 (Measure-Obje..
PowerShell : Get-Content, Set-Content, Out-File (파일 입출력) Get-Content (파일 읽기) Get-Content "C:\TEST.txt" Set-Content (파일 출력) Set-Content "C:\TEST.txt" "저장할 파일 내용" 파이프라인을 이용한 파일 저장 ls "C:\" | Set-Content "C:\TEST.txt" Out-File 명령어를 이용한 파일 저장 (Set-Content와 다르게 모든 값이 저장) ls "C:\" | Out-File "C:\TEST.txt" Get-Content (Microsoft.PowerShell.Management) The Get-Content cmdlet gets the content of the item at the location specified by the path, such as the text ..
PowerShell : 기본 명령어 PowerShell 버전 확인 $PSVersionTable 스크립트가 실행되는 경로 확인 (PowerShell 앱 실행이 아닌 스크립트 실행시에 해당) $PSScriptRoot 클립보드로 복사 Set-ClipBoard "클립보드로 복사되었습니다. CTRL+V로 붙여넣기 해보세요"
PowerShell : Alias - Alias # 기본 Get-Alias # Alias 약칭 찾기 Get-Alias copy # Alias 약칭 찾기 (와일드카드) Get-Alias wh* Get-Alias *p Get-Alias a*p # Alias 본명칭 찾기 Get-Alias -Definition copy-item Get-Alias -Definition *item - Alias 만들기 # ls 명령어를 Set-Alias lsa ls - Alias 삭제 Remove-Alias lsa - 주의점 세션이 끝난 경우 만들었던 Alias는 자동적으로 삭제된다. about_Aliases About Aliases In this article --> SHORT DESCRIPTION Describes how to use alternate name..
PowerShell : 특수문자 $ : 달러 사인 # $ : 변수 할당 $newVar = 10 # $_ : $PSItem의 축약, 파이프라인 뒤로 넘어오는 결과값인 객체를 가리킨다. ls "C:\" | % {$_} # $_.멤버명 : 객체 멤버를 선택 할수도 있다. ls "C:\" | % {$_.name} ` : 그레이브 액센트 사인 # 에러! $str = "인용하자면 "비가 오는 밤에는..." 소설책에서" # 정상 $str = "인용하자면 `"비가 오는 밤에는...`" 소설책에서" # \n New Line 역할 $str = "첫 번째 줄`n두 번째 줄" # \r Carriage Return 역할 $str = "첫 번째 줄`r두 번째 줄" # : 샵 사인 # 한줄 주석 처리 % : 퍼센트 사인 # Foreach문 축약 ls "C:\" ..
PowerShell : Date - 날짜 # 현재 날짜 Get-Date # 현재 날짜 (포맷) Get-Date -Uformat "%Y-%m-%d %H:%M" # 날짜 변경 (포맷) Get-Date -Uformat "%Y-%m-%d %H:%M" -Year 1999 -Hour 19 # 일자로 계산 (Get-Date -Year 2010 -Month 12 -Day 31).DayOfYear # 요일 (Get-Date -Year 2010 -Month 12 -Day 31).DayOfWeek # 날짜 +- 계산 (AddDays / AddMonths / AddYears) (Get-Date -Year 2011 -Month 12 -Day 31).adddays(1) Get-Date (Microsoft.PowerShell.Utility) The Get-Dat..

반응형