posted
29/07/09
By Fredrik Wall
Live Messenger is a stable service, but I have been started
writing on some Backup functions for Social Networks and
I think Live Messenger is a Social Network.
This is a very small function and I got the how to use messenger
information from this post by Jeffery Hicks.
function Backup-MessengerContacts {
$messenger=New-Object -com"Messenger.UIAutomation"
$messenger.mycontacts
}
Backup-MessengerContacts | select FriendlyName,SigninName,Blocked |Export-Csv "C:\messengerContacts.txt"
posted
28/07/09
By Fredrik Wall
I’m working on some tools with a friend of mine and the tools need certutil with SCRoots.
SCRoots are there from the certutil version shipped with Vista.
With certutil version number 6.0.xxxx.
function Get-CertUtilVersion {
########################################################################
# Function: Get CertUtil Version
# Version: 1.0
# Updated: 2009-07-28
# Code By: Fredrik "Dalle" Wall, Riverpoint AB (fredrik[dot]wall[at]riverpoint[dot]se)
########################################################################
$certUtilVer = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($env:windir + "\system32\certutil.exe").ProductVersion
$certUtilVer = $certUtilVer.substring(0,3)
if ($certUtilVer -ge 6.0) { $certUtilVer = "scroots" }
else { $certUtilVer = "no scroots"}
$certUtilVer
}
posted
28/07/09
By Fredrik Wall
This is my Get-OSVersion function.
function Get-OSVersion {
########################################################################
# Function: Get Operating System Version
# Version: 1.0
# Updated: 2009-07-28
# Code By: Fredrik "Dalle" Wall, Riverpoint AB (fredrik[dot]wall[at]riverpoint[dot]se)
########################################################################
$osver = Get-WmiObject win32_operatingsystem
$osver = $osver.version.substring(0,3)
switch ($osver)
{
'5.1' {$osver = "Windows XP"}
'5.2' {$osver = "Windows Server 2003"}
'6.0' {
$path=”HKLM:\Software\Microsoft\Windows NT\CurrentVersion”
$reg=Get-ItemProperty $path
$prodName = $reg.ProductName
if ($prodName -match "Windows Vista") {$osver = "Windows Vista"}
if ($prodName -match "2008") {$osver = "Windows Server 2008"}
}
'6.1' {$osver = "Windows 7"}
default {$osver = "Unknown"}
}
$osver
}
posted
26/07/09
By Fredrik Wall
This will be my first post in a long series of
posts, screencasts and other things related to
PowerShell and .net forms with one of my favorite
tools, Primal Forms (Community Version).

I love this tool because of that It’s so easy to take
a old PowerShell script or a function and make a forms
for It in 5 minutes.
Windows forms tools will draw a bigger audiences to It
then ordinary PowerShell scripts will.
In this first example I will only do a simple form with
a close button and a label that will show the Internet
IP Address.
And then we export the form to PowerShell and get this code:
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.3.0
# Generated On: 2009-07-26 19:37
# Generated By: Fredrik
########################################################################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$groupBox1 = New-Object System.Windows.Forms.GroupBox
$lblIPAddress = New-Object System.Windows.Forms.Label
$btnClose = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$btnClose_OnClick=
{
#TODO: Place custom script here
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = 'Primal Form'
$form1.Name = 'form1'
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 294
$System_Drawing_Size.Height = 266
$form1.ClientSize = $System_Drawing_Size
$groupBox1.Name = 'groupBox1'
$groupBox1.Text = 'Internet Information'
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 269
$System_Drawing_Size.Height = 198
$groupBox1.Size = $System_Drawing_Size
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 13
$groupBox1.Location = $System_Drawing_Point
$groupBox1.TabStop = $False
$groupBox1.TabIndex = 1
$groupBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Controls.Add($groupBox1)
$lblIPAddress.TabIndex = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 185
$System_Drawing_Size.Height = 23
$lblIPAddress.Size = $System_Drawing_Size
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 43
$System_Drawing_Point.Y = 79
$lblIPAddress.Location = $System_Drawing_Point
$lblIPAddress.DataBindings.DefaultDataSourceUpdateMode = 0
$lblIPAddress.Name = 'lblIPAddress'
$groupBox1.Controls.Add($lblIPAddress)
$btnClose.TabIndex = 0
$btnClose.Name = 'btnClose'
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$btnClose.Size = $System_Drawing_Size
$btnClose.UseVisualStyleBackColor = $True
$btnClose.Text = 'Close'
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 207
$System_Drawing_Point.Y = 231
$btnClose.Location = $System_Drawing_Point
$btnClose.DataBindings.DefaultDataSourceUpdateMode = 0
$btnClose.add_Click($btnClose_OnClick)
$form1.Controls.Add($btnClose)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
If we run this code we will get this dumb form.
No information and the close button will not work.
To incorporate my Get-MyInternetIP function
we just add the code for the Get-MyInternetIP code
above the form code.
Function Get-MyInternetIP {
if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient }
$url="http://ip-address.domaintools.com/myip.xml"
$myInternetIP=([xml]($WebClient.DownloadString($url))).dnstools.ip_address
$myInternetIP
}
And then add
$form1.close()
to the
$btnClose_OnClick=
section
And at the en add
$lblIPAddress.Text = Get-MyInternetIP
Thats It!
All the code:
Function Get-MyInternetIP {
if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient }
$url="http://ip-address.domaintools.com/myip.xml"
$myInternetIP=([xml]($WebClient.DownloadString($url))).dnstools.ip_address
$myInternetIP
}
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.3.0
# Generated On: 2009-07-26 19:37
# Generated By: Fredrik
########################################################################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$groupBox1 = New-Object System.Windows.Forms.GroupBox
$lblIPAddress = New-Object System.Windows.Forms.Label
$btnClose = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$btnClose_OnClick=
{
#TODO: Place custom script here
$form1.close()
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = 'Primal Form'
$form1.Name = 'form1'
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 294
$System_Drawing_Size.Height = 266
$form1.ClientSize = $System_Drawing_Size
$groupBox1.Name = 'groupBox1'
$groupBox1.Text = 'Internet Information'
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 269
$System_Drawing_Size.Height = 198
$groupBox1.Size = $System_Drawing_Size
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 13
$groupBox1.Location = $System_Drawing_Point
$groupBox1.TabStop = $False
$groupBox1.TabIndex = 1
$groupBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Controls.Add($groupBox1)
$lblIPAddress.TabIndex = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 185
$System_Drawing_Size.Height = 23
$lblIPAddress.Size = $System_Drawing_Size
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 43
$System_Drawing_Point.Y = 79
$lblIPAddress.Location = $System_Drawing_Point
$lblIPAddress.DataBindings.DefaultDataSourceUpdateMode = 0
$lblIPAddress.Name = 'lblIPAddress'
$lblIPAddress.Text = Get-MyInternetIP
$groupBox1.Controls.Add($lblIPAddress)
$btnClose.TabIndex = 0
$btnClose.Name = 'btnClose'
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$btnClose.Size = $System_Drawing_Size
$btnClose.UseVisualStyleBackColor = $True
$btnClose.Text = 'Close'
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 207
$System_Drawing_Point.Y = 231
$btnClose.Location = $System_Drawing_Point
$btnClose.DataBindings.DefaultDataSourceUpdateMode = 0
$btnClose.add_Click($btnClose_OnClick)
$form1.Controls.Add($btnClose)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
posted
26/07/09
By Fredrik Wall
I’m working on some functions that can help when
working with installation and MSI files.
This one is the first one.
function Clean-Temp {
$myTemp = "$Env:temp"
get-Childitem $myTemp | remove-Item -recurse -force
}
This function deletes everything in the current users temp folder.
No high tech, but nice to have!
posted
26/07/09
By Fredrik Wall
Two very simple function that’s get my IP address and City on the internet.
Function Get-MyInternetIP {
if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient }
$url="http://ip-address.domaintools.com/myip.xml"
$myInternetIP=([xml]($WebClient.DownloadString($url))).dnstools.ip_address
$myInternetIP
}
Function Get-MyInternetCity {
if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient }
$url="http://ip-address.domaintools.com/myip.xml"
$myInternetCity=([xml]($WebClient.DownloadString($url))).dnstools.city
$myInternetCity
}
posted
24/07/09
By Fredrik Wall
This script is an updated version of the
How to Backup Twitter Friends with PowerShell and Excel
post earlier today. In this version I use the
out-Excel function by The Pathological Scripter.
[System.Reflection.Assembly]::LoadWithPartialName(”System.Web") | Out-Null
$userName = "username"
$password = "password"
Function Get-TwitterFriends {
param ($username, $password, $ID)
if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient }
$WebClient.Credentials = (New-Object System.Net.NetworkCredential -argumentList $username, $password)
$page = 1
$Friends = @()
if ($ID) {$URL="http://twitter.com/statuses/friends/$ID.xml?page="}
else {$URL="http://twitter.com/statuses/friends.xml?page="}
do { $Friends += (([xml]($WebClient.DownloadString($url+$Page))).users.user )
$Page ++
} while ($Friends.count -eq 100)
$Friends
}
function out-excel {
param ([string[]]$property,[switch]$raw)
begin {
# start Excel and open a new workbook
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
# initialize our row counter and create an empty hashtable
# which will hold our column headers
$Row = 1
$HeaderHash = @{}
}
process {
if ($_ -eq $null) {return}
if ($Row -eq 1) {
# when we see the first object, we need to build our header table
if (-not $property) {
# if we haven’t been provided a list of properties,
# we’ll build one from the object’s properties
$property=@()
if ($raw) {
$_.properties.PropertyNames | %{$property+=@($_)}
} else {
$_.PsObject.get_properties() | % {$property += @($_.Name.ToString())}
}
}
$Column = 1
foreach ($header in $property) {
# iterate through the property list and load the headers into the first row
# also build a hash table so we can retrieve the correct column number
# when we process each object
$HeaderHash[$header] = $Column
$Sheet.Cells.Item($Row,$Column) = $header.toupper()
$Column ++
}
# set some formatting values for the first row
$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 19
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True
$WorkBook.HorizontalAlignment = -4108
}
$Row ++
foreach ($header in $property) {
# now for each object we can just enumerate the headers, find the matching property
# and load the data into the correct cell in the current row.
# this way we don’t have to worry about missing properties
# or the “ordering” of the properties
if ($thisColumn = $HeaderHash[$header]) {
if ($raw) {
$Sheet.Cells.Item($Row,$thisColumn) = [string]$_.properties.$header
} else {
$Sheet.Cells.Item($Row,$thisColumn) = [string]$_.$header
}
}
}
}
end {
# now just resize the columns and we’re finished
if ($Row -gt 1) { [void]$WorkBook.EntireColumn.AutoFit() }
}
}
Get-TwitterFriends $userName $password | select name,screen_Name,url | out-excel
posted
24/07/09
By Fredrik Wall
Twitter have been cleaning out spamers and some ordinary users got cleaned too.
It can be hard to know wish Twitter Friends you had yesterday and whish you got today.
From now on I will use a PowerShell script that I wrote today.
I did some changes to James O’Neils Twitter Function Get-TwitterFriend to
get It to work with more then 100 Friends.
And then Export it to a csv file and imported it in to Excel.
This can be handled with a export or import to Excel function.
[System.Reflection.Assembly]::LoadWithPartialName(”System.Web") | Out-Null
$userName = "username"
$password = "password"
$txtFile = "c:\textfile.txt"
Function Get-TwitterFriends {
param ($username, $password, $ID)
if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient }
$WebClient.Credentials = (New-Object System.Net.NetworkCredential -argumentList $username, $password)
$page = 1
$Friends = @()
if ($ID) {$URL="http://twitter.com/statuses/friends/$ID.xml?page="}
else {$URL="http://twitter.com/statuses/friends.xml?page="}
do { $Friends += (([xml]($WebClient.DownloadString($url+$Page))).users.user )
$Page ++
} while ($Friends.count -eq 100)
$Friends
}
Get-TwitterFriends $userName $password | select name,screen_Name,url | export-csv $txtfile
Then start Excel
and Open, file types .txt and chose your file.

In the text import Wizard step 1
Change Start import at row 1 to 2.
Then we do not get the row with PowerShell’s information.

In the text import Wizard step 2
Change Delimiters from Tab to Comma

When Excel opens you got all of your Friends in an excel document.
To view whole names in columns just push down right arrow over
the first row and to the left of the first column.
No you have the worksheet marked and then just double click on the
line between column A and B.


The first Friends on the list is the last Friends you have added to
Twitter.
I hope this will help you!
My next post will be a PowerShell and .net Windows Forms App
for this.
posted
23/07/09
By Fredrik Wall
Det pratas mycket om säkerhet och molntjänster på bloggar, i artiklar
och på twitter just nu. Man kan få uppfattningen när man skummar
detta att själva molntjänst grejen är osäker.
Att det skulle vara själva molntjänst fenomenet som är osäkert håller
jag inte med om.
Visst är det så att det innebär en viss risk att logga in dessa
molntjänster över internet. Särskilt om man loggar in på dessa tjänster utan
att anslutningen är krypterad.
Man ska vara medveten om att all information man skriver in på webbplatser
åker över internet på ett eller annat sätt.
De vanligaste molntjänsterna är vanlig webbmail.
T ex Gmail, Live Mail, Loopia Webbmail, Surftown Webmail eller Microsoft Web Access.
- Gmail använder https på hela sin webbmail.
- Microsoft använder https för själva inloggningen.
- Loopia använder http för hela sin webbmail.
- Surftown skickar vidare en efter inloggning till mailen på https.
- Microsoft Web Access via olika hostingleverantörer
använder oftast en krypterad anslutning via https.
Ett av de vanligare misstagen som görs är att man använder enkla
lösenord på dessa tjänster och tror att det är ändå ingen som kommer att
vilja komma åt mitt konto. Och misstag nummer 2 är att man använder samma
lösenord på flera tjänster, hemma datorn och på jobbet.
Vanliga lösenord:
- password
- lösenord
- “hundens namn”
- “förnamn”
- “efternamn”
- “barnets namn”
Dessutom är det inte så enkelt att den som vill ta sig in på ditt konto bara sitter
och knappar in lösenord på måfå. Det finns program för detta som använder
stora lösenordslistor.
Detta gäller naturligtvis vilka tjänster som helst som ligger på internet.
Bloggar, e-handelsplatser, affärssystem, fjärrstyrnings system etc.
För att enkelt försvåra för de som försöker att ta sig in på dina
olika konton på olika system så bör man använda så svåra lösenord som möjligt.
Med både bokstäver (stora och små), siffror och specialtecken.
Och lösenorden ska vara så långa som möjligt (över 15 tecken är bra) för då är det
troligt att verktygen inte klarar att ta gissa dina lösenord eller att den som kör
programmet inte orkar vänta länge.
Nu tänker du säkert att men f*n inte kan jag ha 20 lösenord som är supersvåra när
jag knappt kommer ihåg ett sådant.
Man kan skriva ner sina lösenord.Fördelen med att skriva ner ett lösenord är
att man enkelt kan komma ihåg det, oavsett längd eller komplexilitet.
Nackdelen är att det är lätt att se även för andra.
Som tur är finns det program som löser detta åt dig.
Ett program som jag själv använder flitigt är KeePass.
KeePass utvecklades från början av säkerhets experten Bruce Schneier
och hette då Password Safe. Nu är det ett Open Source Projekt
och utvecklas flitigt.
I enkla drag så lagras dina sorterade lösenord i en krypterad databas.
För varje nytt konto man lägger upp så kan man slumpa fram lösenord och
välja hur svåra lösenordena ska vara.
Mer om detta hittar man på KeePass hemsida.
Det finns lite olika krypterings sätt man kan använda och det finns dessutom
flera olika sätt att skydda databasen.
KeePass finns i i en mängd olika versioner för olika operativsystem och
det finns även standalone versioner som kan köras direkt ifrån ett USB minne.
Detta gör att man alltid kan bära med sig sina lösenord och slipper sedan installera
program för att komma åt dem. Dock ska man akta sig för att köra programmet på vilken
dator som helst. Men man ska ju alltid vara försiktig med allt man gör på en okänd dator.
posted
23/07/09
By Fredrik Wall
Windows 7 and Windows Server 2008 R2 has been released to manufacturing (RTM).
You will find the blog post from the Windows 7 team here.
And the blog post from the Windows Server 2008 R2 team here.
At the Virtualization team blog you will find a great blog post about the RTM too.
You will find that post here.
Here is a sneak peak of the RTM announcement.
See Steve Ballmer signing the gold RTM DVD’s.
Windows 7 Sneak-Peak from MGX