Posts tagged ‘powershell’

18 posts; newest first

Finding IIS Worker Processes

powershell iis

How do we find out if there’s a worker process for an application pool? Note that there can be more than one worker process for each application pool. Note also that a worker process can host multiple web applications.

» read more

PowerShell and enums

powershell

PowerShell has a really cool feature where it’ll coerce a string into an enum value. I’ll demonstrate by exporting a certificate from the Windows certificate store:

» read more

PowerShell tip: Deleting certificates

powershell
$certs = Get-ChildItem cert:\LocalMachine\My | where { $_.Subject –like 'CN=Victim*' }
foreach ($cert in $certs) {
    $store = Get-Item $cert.PSParentPath
    $store.Open('ReadWrite')
    $store.Remove($cert)
    $store.Close()
}

The first line finds certificates with the matching subject. The loop goes through those certificates, using .NET class library methods to delete them.

» read more

PowerShell Closures

powershell
# Create a script block. It doesn't capture $x.
$x = 'A'
$sb = { Write-Host $x }

# Change the value of $x and run the script block. Note that it displays the current value.
$x = 'B'
& $sb                  # ... B

# Create a closure.
$closure = $sb.GetNewClosure()

# Change the value of $x.
$x = 'C'

# Run the closure. It displays the original value. Success.
& $closure             # ... B

# For comparison, run the script block. Nope. Still tracking the current value.
& $sb                  # ... C
» read more

PowerShell: ImportSystemModules

powershell

I’ve been using PowerShell as a better Command Prompt for a while now. Increasingly, however, it’s one of the first tools I reach for when I come across a problem, rather than being an afterthought.

» read more