29 Eylül 2020 Salı

Powershell Write-Host

Giriş
Açıklaması şöyle
In a nutshell, Write-Host writes to the console itself. Think of it as a MsgBox in VBScript. Write-Output, on the other hand, writes to the pipeline, so the next command can accept it as its input.

Powershell Read-Host

Giriş
Bu komutun tersi Write-Host. Read-Host konsoldan girdi okur

Örnek
Şöyle yaparız
$software = Read-Host "Software you want to remove"

23 Eylül 2020 Çarşamba

Powershell Function Tanımlama

Giriş
Powershell ile ScriptBlock tanımlanabiliyor. Ayrıca Function da tanımlanabiliyor.
ScriptBlock Invoke-Command -ScriptBlock $MyScriptBlock şeklinde kullanıbiliyor.

ScriptBlock Tanımlama
Örnek
Şöyle yaparız
$Credentials = ...
$Computeters = ...

foreach ($Computer in $Computers

  $MyScriptBlock = {
    param($Computer,$Credentials)
    ...
  }
  
  Invoke-Command -ScriptBlock $MyScriptBlock -ArgumentList ($Computer, $Credentials)
}
Örnek
Şöyle yaparız
function Check-Update {
  Param(
    [Parameter(Mandatory=$True, Valuefrompipeline=$True)]
[Validatenotnullorempty()]
[String]$Path ) $IsGood=$false if ($(Test-Path $Path) -and $Path.EndsWith(".msu")) { ... } else { Write-Error -Message "Update file: $path doesn't exist as a valid update file" } }
Örnek - Aynı script
Şöyle yaparız
Function New-Ping {
    
    Param(
        [Parameter(Mandatory)]
        [string]$ComputerName,
        [Parameter(Mandatory)]
        [int]$Intervall
    )

    while ($true) { 
        Test-Connection $ComputerName -Count 1
        Start-Sleep -MilliSeconds $Intervall 
    }
}
Çağırmak için şöyle yaparız
New-Ping ServerName 500

Windows ping komutu

Giriş 
Açıklaması şöyle
By default the time delay between two pings is equal to 1 second.

Powershell Test-Connection

Örnek 
Şöyle yaparız
while ($true) { Test-Connection ServerName -Count 1 ; Start-Sleep -MilliSeconds 500 }

Snap-in

fsmgmt.msc share edilen dizinleri gösterir.
lusrmgr.msc kullanıcıları ve grupları gösterir

Powershell Remove-Item - Dosya ve Dizin Siler

Giriş
Açıklaması şöyle
Remove-Item *.tmp or any of its aliases like rm *.tmp, del *.tmp
Örnek
Şöyle yaparız
CMD Example: del TestItem.txt

Powershell Example: remove-item TestItem.txt
Örnek
Şöyle yaparız
$mydirectory ="..."
$excludedirectory1 ="..."
$excludedirectory2 ="..."
Remove-Item $mydirectory\* -Exclude $excludedirectory1 $excludedirectory2 -Recurse -Force -ErrorAction Ignore