Alexandria University - Faculty of Science
Course: Operating Systems
Lecturer: Dr. Ahmed Younes
Example
PowerShell:
To get the policy of execution of powershell script:
Get-ExecutionPolicy
Set-ExecutionPolicy -Scope CurrentUser "then" enter policy
Viewing Objects in a Directory:
Get-ChildItem -path C:\Users\Carnival\Desktop
Get-ChildItem C:\Users\Carnival\Desktop -Recurse
Get-ChildItem -Path C:\Users\Carnival\Desktop -Recurse -Include ‘*.txt’ | Where-Object
{($_.LastWriteTime -gt '2024-03-28')}
Pipe:
"Welcome to powershell" | Out-File C:\Users\Carnival\Desktop\OS\LAB\file2.txt
Get-Service | WHERE {$_.status -eq "Running"} | SELECT displayname
Creating Files and Folders:
New-Item -Path 'C:\Users\Carnival\Desktop\os' -ItemType Directory
New-Item -Path 'C:\Users\Carnival\Desktop\oslab.txt' -ItemType File
Delete file or directory:
Remove-Item -Path 'C:\Users\Carnival\Desktop\oslab.txt'
Remove-Item -Path 'C:\Users\Carnival\Desktop\os' -Recurse //delete dir and subdir
Alexandria University - Faculty of Science
Course: Operating Systems
Lecturer: Dr. Ahmed Younes
Get-ChildItem -Path C:\Users\Carnival\Desktop\Newfolder -Recurse -Include ‘lab*’ |
Where-Object {($_.LastWriteTime -gt '2024-03-28')} | Remove-item -force
Copying Files and Folders:
Copy-Item -Path ‘C:\Users\Carnival\Desktop\OS\cp.txt’ -Destination
‘C:\Users\Carnival\Desktop\OS\file3.txt’
Moving Files and Directories:
Move-Item -Path "C:\Users\Carnival\Desktop\OS\cp.txt" -Destination
"C:\Users\Carnival\Desktop\DB 2024\cp.txt"
Rename:
Rename-Item -Path "C:\Users\Carnival\Desktop\os.txt" -NewName "labos.txt"