Kasowania pliku przy pomocy PowerShell
Kasowania pliku przy pomocy PowerShell
Jak użyć komend PowerShell do usunięcia pliku
# Jak użyć komend PowerShell do usunięcia pliku
Remove-Item -Path "C:\test\TestFile.txt"
Można również użyć symbolu wieloznacznego (wildcard) '*' aby usunąć wiele pozycji. Przykłąd, polecenie to usuwa wszystkie pliki w folderze C: \ test:
# Komenda PowerShell do kasowania wymuszonego wszystkich plików
# w folderze
Remove-Item -Path "C:\test\*.*"
Komenda Force wymusza usunięcie plików nie potrzeba potwierdzać w przypadku atrybuty tylko do odczytu.
# Komenda PowerShell do usunięcia wszystkich plików
Remove-Item -Path "C:\test\*.*" -Force
Komendad -recurse kasowanie plików i folderów ze wskazanej lokalizacji
# Komendad -recurse kasowanie plików i folderów ze wskazanej lokalizacji
Remove-Item -Path "C:\test\*.*" -recurse
First script - PowerShell
We create the first script in powershell
Create a new file named first script.ps1
| Write-Host "Hello, World!" |
Save the file and open PowerShell window.
There are 4 settings of policies:
-
Restricted – Scripts won’t run. Period. (Default setting)
-
RemoteSigned – Locally-created scripts will run. Scripts that were created on another machine will not run unless they are signed by a trusted publisher.
-
AllSigned – Scripts will only run if signed by a trusted publisher (including locally-created scripts).
-
Unrestricted – All scripts will run regardless of who created them and whether or not they are signed.
We change policies RemoteSigned
Set-ExecutionPolicy RemoteSigned
correct syntax to run the script
& "c:\folder\script.ps1
c:\folder\script.ps1
incorrect syntax to run the script
PS C:\folder> script.ps1
writing scripts Powershell
writing scripts Powershell
Powershell scripts written as a text file with the extension .ps1. Run the script from the PowerShell console:
Run PS script:
write full path PS C:\windows\script\test_script.ps1
Strona 86 z 126







