Categories

10387

Service Startup History

If we need to look at the startup history of a service we can find the information in the event log


 


001
002
003
004
005
006
function Get-ServiceStartupHistory {
param ([string]$name ) 

Get-EventLog -LogName System | where {(($_.EventId -eq 7035) -or ($_.EventId -eq 7036)) -and $_.Message -like "The $($name)*"}

}

 


I’ve done this as a function as I’m moving all my service based scripts into a module. Eventually, all my scripts will be in modules


Technorati Tags: ,,,

Computername parameter

This is something I’ve been meaning to share for a while.  Many of the cmdlets in PowerShell v2 get an explicit remoting capability via the computername property.

get-help * -Parameter computername | sort name

Clear-EventLog
Connect-WSMan
Disconnect-WSMan
Enter-PSSession
Get-Counter
Get-EventLog
Get-HotFix
Get-Process
Get-PSSession
Get-Service
Get-WinEvent
Get-WmiObject
Get-WSManInstance
Invoke-Command
Invoke-WmiMethod
Invoke-WSManAction
Limit-EventLog
New-EventLog
New-PSSession
New-WSManInstance
Receive-Job
Register-WmiEvent
Remove-EventLog
Remove-PSSession
Remove-WmiObject
Remove-WSManInstance
Restart-Computer
Set-Service
Set-WmiInstance
Set-WSManInstance
Show-EventLog
Stop-Computer
Test-Connection
Test-WSMan
Write-EventLog

This is going to take a bit of working through but this expands the capabilities of PowerShell quite nicely.

Technorati Tags: ,,,

How many bytes?

I was playing around with PowerShell and started thinking about the kb, mb etc values and I realised I didn’t know what they really looked like.  1kb is 1024 but it gets very hazy after that. So how could I see the values stacked up

1kb,1mb,1gb,1tb,1pb | foreach{"$_".PadLeft(16)}

works.  We feed in the list of values. Pipe into foreach and use string substitution to display.  That will left justify the display.  By padding the left of the display with spaces we can effectively right justify the field to give

            1024
         1048576
      1073741824
   1099511627776
1125899906842624

So now you know what the stack of xbytes looks like

We can also achieve the same effect using

1kb,1mb,1gb,1tb,1pb | foreach{"{0,16}" -f $_}

Hmm.. wonder how effort is involved to produce a Tower of Hanoi script from this

Technorati Tags: ,,