PowerShell: Adding More Fonts

Posted 10 CommentsPosted in PowerShell

Tired of using the boring default fonts in PowerShell? There are more monospaced fonts on your system. You just need to allow the console to use them. Here’s how: $key = ‘HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont’ Set-ItemProperty -Path $key -Name ‘0’ -Value ‘Lucida Console’ Set-ItemProperty -Path $key -Name ’00’ -Value ‘Courier New’ Set-ItemProperty -Path $key -Name ‘000’ -Value […]

PowerShell: Check Active Internet Connection

Posted Leave a commentPosted in PowerShell

If your machine is connected to the Internet more than once, let’s say cabled and wireless at the same time, which connection is used? Here’s a function that tells you: function test-ipmetric { Get-WmiObject Win32_NetworkAdapter -Filter “AdapterType=’Ethernet 802.3′” | ForEach-Object { $_.GetRelated(‘Win32_NetworkAdapterConfiguration’) } | Select-Object Description, Index, IPEnabled, IPConnectionMetric }

PowerShell: More Can Be Dangerous

Posted Leave a commentPosted in PowerShell

You might know the more.com tool: when you pipe output to more.com, the output is displayed page by page: PS> Get-EventLog -LogName System | more However, more can be dangerous as you see here. You will not get any results for a long time, and your CPU load increases. more.com first collects all results before […]

PowerShell: Sending Emails Securely (via SSL)

Posted Leave a commentPosted in PowerShell

Here is a sample that uses the live.com freemailer (formally called Hotmail) which does require a secure connection: PS> Send-MailMessage -Body ‘My mail message can contain special characters: äöüß’ -From youraccountname@hotmail.com -to someone@somewhere.com -Credential youraccountname@hotmail.com -SmtpServer smtp.live.com -Subject ‘Sending Mail from PowerShell’ -Encoding UTF8 -UseSsl Note that PowerShell v3 Send-MailMessage accepts UTF8 directly so you […]

PowerShell: Analysing System Restarts

Posted 1 CommentPosted in PowerShell

To find out when a system restarted and why, use the below code to extract the relevant information from the System event log: Get-EventLog -LogName System -ComputerName Server1 | where {$_.EventId -eq 1074} | ForEach-Object { $rv = New-Object PSObject | Select-Object Date, User, Action, Process, Reason, ReasonCode, Comment, Message if ($_.ReplacementStrings[4]) { $rv.Date = […]