Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

https://www.tutorialspoint.com/powershell/index.htm


Enable the script to run

link
in powershell

Set-ExecutionPolicy Unrestricted


Code Block
titleset-ExecutionPolicy
collapsetrue
PS C:\windows\system32> Get-ExecutionPolicy
Restricted
PS C:\windows\system32> Set-ExecutionPolicy Unrestricted

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): yes
PS C:\windows\system32> Get-ExecutionPolicy
Unrestricted
PS C:\windows\system32>


Hello World
create

create a .ps1 file

>>>> write-host "hello world"


use ISE

Image Modified

run

> "hello world.ps1"

or

>& '.\hello world.ps1'

Print out

write-host "Welcome to my script"


Loop forLink


Loop while

write-host "Welcome to my script"

while ($true){

#test-connection 172.16.128.2
ping 172.26.128.2 -n 1 -l 1472
Start-Sleep -Seconds 6

}

create a ping and curl loopInvoke-WebRequest

for ($i=0; $i -lt 30; $i++){
#Start-Process powershell.exe -ArgumentList "ping 172.26.128.2 -n 100 -l 1472"
Start-Process powershell.exe -ArgumentList "Invoke-WebRequest 172.26.128.2 -UseBasicParsing"
Start-Process powershell.exe -ArgumentList "Invoke-WebRequest 172.26.128.2 -UseBasicParsing"
Start-Process powershell.exe -ArgumentList "Invoke-WebRequest 172.26.128.2 -UseBasicParsing"
Start-Process powershell.exe -ArgumentList "Invoke-WebRequest 172.26.128.2 -UseBasicParsing"
Start-Sleep -Seconds 1
}