PowerShell Komentowaie
Komentarze w PowerShell
Komentowanie pojedynczej linii - używamy znaku #:
| # w ten sposób komentujemy pojedynczą linię w PowerShell |
Komentowanie blokowe w PowerShell
|
<# this is a first line of comment
this is a second line of comment
this is a third line of comment
.
.
.
this is a last line of comment
#>
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
Shrink Databases MSSQL
Shrink database MSSQL
before using shrink check recovery model - set recovery model to simple
before shrink
after shrink
Recovery model
simple for shrink log file
select a shrink of server management studio
Change the date on the log
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






