Saturday 9 March 2013

Finding your WiFi password from Windows 7

To find your password for a WiFi network you've already connected to in Windows 7 do the following:

Click on the Network icon (shown as seen when connected to WiFi):


Select "Open Network and Sharing Center"


Select "Manage wireless networks" in the left hand pane


Double click the desired WiFi network


Select the "Security" tab


Tick the "Show characters" check box


Make a note of the password


Click "Cancel" to prevent any changes being saved and close any open windows from the previous steps

Thursday 19 July 2012

LttP: Powershell Games 2012 - Beginner Event 10

Here goes my entry for Beginner Event 10:

for($i=0;$i -lt 3; $i++){(Get-Counter -ListSet Processor).Paths | Get-Counter | Out-File (Join-Path ([Environment]::GetFolderPath("mydocuments")) $env:COMPUTERNAME"_ProcessorCounters.txt") -Append;Start-Sleep 5}

I went for the "one-liner" option basically just to help me get into the habit of cleaning my own code up a bit.

This one was quite fun really, it took me a few tries with Out-File to realised I needed the "-Append", as I'm used to using Add-Content instead.

Also, the construction of the path threw me for a minute, until I remembered about "Join-Path".

Time to read what the Expert has to say :)

UPDATE:

The results are right, but the method is a bit...wonky.

Firstly, I could've just used the "-SampleInterval" and "-MaxSamples" switches with the "Get-Counter" cmdlet, instead of doing a For loop with a "Start-Sleep".

Secondly, "[Environment]::GetFolderPath("mydocuments")" isn't strictly native Powershell, it pulls in the .NET framework.  I was going to go with the way the Expert did, but I let my self-doubt creap in when I read the Scripting Wife's comments.

Unfortunately I was late to the party (LttP) so I won't ever really know how I would've been scored for real, but I've learned quite a bit and had some fun with it.

I'm really looking forward to the games next year, and then I'll see how I do for real!

LttP: Powershell Games 2012 - Beginner Event 9

Here's my entry for Beginner Event 9:

Get-EventLog -LogName Application -EntryType "Information" -InstanceId 10001 -Source "Microsoft-Windows-Winsrv" | Format-Table -Property "TimeGenerated","ReplacementStrings" -AutoSize

I'm pretty confident that I'm there, as it's as filtered as possible without restricting to a given application that causes the error.

I did have to follow the tip in the comments about how to create the item in the log and admittenly I was pretty frustrated with this one up to that point.  Then using the "Details" part of the Event Viewer GUI helped me find the "proper" source name.

Anyway, time to see the expert commentary.

LttP: Powershell Games 2012 - Beginner Event 8

Beginner Event 8 has me a bit worried, as I think it's a bit easy.  That normally means I've missed something big and, normally, painfully obvious...

As far as I can tell the design points boil down to this:
  • Write the output to the host
  • Check if the machine is a laptop or desktop based on hardware
  • Only run it on the local computer
  • If it needs admin rights, check that it's running as admin
  • Use a simple function that returns a Boolean value
This means that the whole "inventory of machine on the network" part is a red-herring, and that what I should end up with is something fairly simple.

Here's my thought process on how I tackled those design points:
  • Build up my "message" and use Write-Host to output it at the end
  • Check for a battery using WMI (there is probably a WMI class for that...)
  • Local computer only...no problem
  • Get-WMIObject doesn't need admin rights...so I'm good here so far
  • I'll use a function to work out if the machine has a battery, then use an If statement to amend the message accordingly
Turns out I was right about WMI and there is a Win32_PortableBattery class.  When I run it on my desktop I get nothing, and an error is thrown when trying to run the following:

Get-WMIObject Win32_PortableBattery | Get-Member

That looks good to me, because my desktop doesn't have a portable battery. 

I checked Get-WMIObject Win32_PortableBattery on a laptop and it returned results so, armed with that confidence I charged off and wrote the following to become my "entry":

Function Is-Laptop
{
 If(Get-WMIObject Win32_PortableBattery)
 {
  Return $true
 }
 else
 {
  Return $false
 }
}

$comupterType="desktop"

If(Is-Laptop)
{
 $comupterType="laptop"
}

$Message=$Env:COMPUTERNAME
$Message+=" is a "
$Message+=$comupterType

write-host $Message

Time to read the expert commentary.

UPDATE:

I'm not sure how I would've scored as I used a different WMI class than the expert, and therefore a slightly different approach for figuring out if a machine was a desktop or laptop.

In my entry I basically said that if the machine has a portable battery then it's a laptop; which isn't strictly true because of tablets and slates (although not all that common); but I considered it a reasonable assumption.

LttP: Powershell Games 2012 - Beginner Event 7

Beginner Event 7 had me delving into the "new" logging system and scratching my head with regards to what a "hidden log" might be.

I've taken it to mean a Debug / Analytic log, and as such my "entry" follows:

Get-WinEvent -ListLog * -Force -EA 0 | Where-Object {($_.IsEnabled -eq $true) -and ($_.RecordCount)} | Sort-Object RecordCount -Descending | Format-Table -Property "LogName","RecordCount" -AutoSize -Wrap

Time to check the expert blog...

UPDATE:

It would appear I didn't need the "-Force" according to the expert, and also I could loose the "-eq $true" from my Where-Object clause (as IsEnabled is already a boolean.)

Wednesday 18 July 2012

LttP: Powershell Games 2012 - Beginner Event 6

Well, Beginner Event 6 looks quite familiar.  I've had to do exactly this before, albeit with a different output.  Anyway my "entry":

[datetime]$LastBootTime = (Get-WmiObject Win32_OperatingSystem).ConvertToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime)
$UpTime = New-TimeSpan -Start $LastBootTime -End (Get-Date)

$Message="The computer "
$Message+=$env:COMPUTERNAME
$Message+=" has been up for "
$Message+=$UpTime.Days
$Message+=" days "
$Message+=$UpTime.Hours
$Message+=" hours "
$Message+=$UpTime.Minutes
$Message+=" minutes, "
$Message+=$UpTime.Seconds
$Message+=" seconds as of "
$Message+=(Get-Date).ToString()

Write-Host $Message