Go to ...


A Better Technical Repository

RSS Feed


Powershell: Set the script running security level

Using the Set-ExecutionPolicy Cmdlet Changing the Windows PowerShell Script Execution Policy   The Set-ExecutionPolicy cmdlet enables you to determine which Windows PowerShell scripts (if any) will be allowed to run on your computer. Windows PowerShell has four different execution policies: Restricted – No scripts can be run. Windows PowerShell can be used only in interactive

Programming: A powershell way to check to see if a service has stopped and then start it.

To check to see if a service is running and then start it if it is not, create a powershell file with the following code. $ServiceName = ‘YourExactServiceName’ $arrService = Get-Service -Name $ServiceName while ($arrService.Status -ne ‘Running’) { Start-Service $ServiceName write-host $arrService.status write-host ‘Service starting’ Start-Sleep -seconds 60 $arrService.Refresh() if ($arrService.Status -eq ‘Running’) { Write-Host

Powershell: Send keyboard input to the screen

Here is a very basic way to send keyboard inputs to the screen on a looped time interval: while ($true) { $minutes = 1 $myShell = New-Object -com “Wscript.Shell” for ($i = 0; $i -lt $minutes; $i++) { Start-Sleep -Seconds 30 $myShell.sendkeys(” “) } }

Powershell: Creating an endless loop in your script

Sometimes when scripting you need to create a never ending loop while your script either waits for some other task to complete or repeats a task over and over again. There are two ways people tend to go about creating loops in Powershell, but one of them will eventually leave your script in a heap.

Older Posts››