Created
January 31, 2018 13:44
-
-
Save JeffWouters/044e27236a118b0d08fba8f86659205b to your computer and use it in GitHub Desktop.
While Until
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Install-Module -Name PSScriptAnalyzer -Force | |
| Get-Command -Module PSScriptAnalyzer | |
| Invoke-ScriptAnalyzer -Path D:\PowerShell\script.ps1 | |
| Invoke-ScriptAnalyzer -Path D:\PowerShell\script.ps1 | Out-GridView | |
| (1..10 | foreach { | |
| measure-command { | |
| D:\PowerShell\script.ps1 | |
| } | |
| } | Measure-Object -Property Milliseconds -Average | |
| ).average |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #1:1 - Non-interactive | |
| Invoke-Command -ComputerName server1 -ScriptBlock { | |
| Get-Process | |
| } | |
| #1:n - Non-interactive | |
| Invoke-Command -ComputerName server1,server2,server3 -ScriptBlock { | |
| Get-Process | |
| } | |
| #1:1 - Interactive | |
| $PSSession = New-PSSession -ComputerName server1 | |
| Enter-PSSession -Session $PSSession | |
| #Kun je alle code uitvoeren die je wilt | |
| Exit-PSSession | |
| Remove-PSSession $PSSession | |
| #1:n - (semi)Interactive | |
| $PSSession = New-PSSession -ComputerName fs1,db1,ctx1,ctx2,ctx3 | |
| Invoke-Command -Session $PSSession -ScriptBlock { | |
| #Voor alle servers | out-file d:\logs\blaat.log | |
| } | |
| Invoke-Command -Session ($PSSession| where {$_.computername -like "ctx*"}) -ScriptBlock { | |
| #Stop process | |
| } | |
| Invoke-Command -Session ($PSSession | where {$_.computername -like "db*"}) -ScriptBlock { | |
| #stop database | |
| } | |
| Invoke-Command -Session ($PSSession | where {$_.computername -like "fs*"}) -ScriptBlock { | |
| #Verwijder bestandje | |
| } | |
| $Body = Invoke-Command -Session $PSSession -ScriptBlock { | |
| #Maak report | convertto-html -fragment | |
| } | |
| Send-MailMessage -Body $Body -Subject Report |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function New-user | |
| { | |
| <# | |
| .SYNOPSIS | |
| Korte omschrijving. | |
| .DESCRIPTION | |
| Korte omschrijving + lange omschrijving. | |
| .EXAMPLE | |
| .\Script.ps1 -Name Lars -WelcomeName Welkom | |
| .NOTES | |
| #> | |
| param ( | |
| [parameter( | |
| Position=0, | |
| Mandatory=$true | |
| )] | |
| [ValidateNotNullOrEmpty()] | |
| [string]$Name, | |
| [parameter( | |
| Position=1, | |
| Mandatory=$false | |
| )] | |
| [ValidateSet('Welcome','Welkom')] | |
| [string]$WelcomeName = "Welcome" | |
| ) | |
| try { | |
| $HomeDir = New-Item -Name $Name -ItemType Directory | |
| Push-Location $Homedir.FullName | |
| try { | |
| $Welcome = New-Item -Name "$WelcomeName.txt" -Value "Welcome, $Name!" | |
| } | |
| catch | |
| { | |
| Pop-Location | |
| Write-Error $_ | |
| } | |
| } | |
| catch | |
| { | |
| Write-Error $_ | |
| } | |
| } | |
| # Inlezen van CSV | |
| # Functie aanmaken lokale gebruiker | |
| #Tip: ConvertTo-SecureString | |
| # Functie aanmaken directory | |
| # Functie zetten rechten voor lokale gebruiker op directory | |
| #Tip: powershell acl addaccessrule | |
| # Rapportage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $Count = 1 | |
| do | |
| { | |
| if ($Count -gt 10) | |
| { | |
| exit | |
| } | |
| else | |
| { | |
| if (Get-Process -Name notepad -ErrorAction SilentlyContinue) | |
| { | |
| Write-Output "Notepad is gevonden" | |
| Start-Sleep -Seconds 1 | |
| $Count++ | |
| } | |
| else | |
| { | |
| exit | |
| } | |
| } | |
| } | |
| while (Get-Process -Name notepad -ErrorAction SilentlyContinue) | |
| #Maximaal 5 keer controleren, slaap van XX seconden | |
| # Do/Until : Toon text tot notepad is geopend | |
| # Do/while : Toon text tot notepad is gesloten |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment