File Management at 12:52
This commit is contained in:
67
6.File_Management/File Management with PowerShell.md
Normal file
67
6.File_Management/File Management with PowerShell.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# File Management with PowerShell
|
||||
|
||||
## Get-ChildItem
|
||||
|
||||
Get the content of a curent directory
|
||||
Alias = ls
|
||||
|
||||
```powershell
|
||||
Get-ChildItem
|
||||
|
||||
Get-ChildItem C:\Windows
|
||||
```
|
||||
|
||||
## Set-Location
|
||||
|
||||
Change current directory
|
||||
Alias = cd
|
||||
|
||||
```powershell
|
||||
Set-Location
|
||||
```
|
||||
|
||||
## ACL
|
||||
|
||||
Windows Access Control Lists (ACLs) are a core security
|
||||
mechanism used to control access to files,
|
||||
folders, and other system objects.
|
||||
An ACL defines which users or groups are allowed
|
||||
or denied specific permissions, such as read,
|
||||
write, modify, or execute.
|
||||
Each ACL is made up of Access Control Entries (ACEs)
|
||||
that explicitly grant or restrict these permissions.
|
||||
By using ACLs, Windows ensures that only authorized users can access or modify
|
||||
resources, helping to protect system integrity and sensitive data.
|
||||
|
||||
### Get-Acl
|
||||
|
||||
for listing permision for a file
|
||||
|
||||
```powershell
|
||||
Get-ACL "C:\mrsh\test.ps1"
|
||||
|
||||
$file = Get-ACL
|
||||
|
||||
$file.Access
|
||||
|
||||
Get-ACL "C:\mrsh\test.ps1" | Format-List
|
||||
```
|
||||
|
||||
### Set-ACL
|
||||
|
||||
```powershell
|
||||
$acl = Get-Acl "C:\mrsh\test.ps1"
|
||||
$permission = "Administrator", "FullControl", "Allow"
|
||||
$accessRule = New=Object System.Security.AccessControl.FileSystemAccessRule $permission
|
||||
$acl.SetAccessRule($accessRule)
|
||||
|
||||
Set-ACL "C:\mrsh\test.ps1" $acl
|
||||
```
|
||||
|
||||
## File size
|
||||
|
||||
```powershell
|
||||
$fileSize = Get-ChildItem -Path "C:\mrsh\test.ps1" -Recurse -Force | Measure-Object -Property Length -Sum
|
||||
|
||||
$fileSize.Sum/1KB
|
||||
```
|
||||
Reference in New Issue
Block a user