17 Jul 2009 @ 1:57 PM 
When I don’t have any real projects to work on I make up stupid tasks to build to keep me occupied. Here is an other one ;-) the RSS feed reader. First I build the script with a external xml script that you needed to load in order to execute the rest of the script so you could use a String method to  read the XML file form a URL. This didn’t work! It was nasty….

<Types>
  <Type>
    <Name>System.String</Name>
      <Members>
        <ScriptMethod>
          <Name>GetRss</Name>
          <Script>
            $wc = New-Object Net.WebClien
            ([xml] ($wc.DownloadString($this))).rss
          </Script>
        </ScriptMethod>
      </Members>
  </Type>
</Types>

So after a period of trail and error I made this line:

$rss = [xml](new-object System.Net.WebClient).DownloadString($Url)

And of course ones I found the solution I got the same line from my friend “Google” ..snif….snif.. I also added some forms to make it look good. There were two things I couldn’t  figure out.

  1. How can i display HTML output without using Internet Explorer
  2. Why doesn’t it work with Wordpress RSS feeds? The discription field can not be parsed to HTML because it doesn’t contain any data.

These questions bug me so if any of you know the answer to the problems above don’t hesitate to comment to this post.

How does the script work?

First the script reeds the feed from the URL with the XML file and then reeds the feeds from the channel in the VAR  $feeds .

Then the form is build with all it’s objects like $listbox, $textbox. Also a handler is added to the form. It detects when Return is pressed  and when so the form shows de body of the selected post title.

image

What was I thinking?

When I was half way building this script I thought what if I use this feed reader on my servers to read an internal blog. Than I could give my servers commands to execute trough a blog…. Ok it is far fetched but I think it can work and that’s my point, Powershell has some boundaries but most of them are in your head I think.

# Select a post title and press return to get the
# post body text.
$Url = "http://blogs.msdn.com/powershell/rss.xml"
$rss = [xml](new-object System.Net.WebClient).DownloadString($Url)
$feeds = $rss.rss.channel.item

[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$form = new-object windows.forms.form
$form.Text = "RSS titles"
$form.StartPosition = "CenterScreen"
$form.Size = New-Object System.Drawing.Size(600,400)
$form.KeyPreview = $true

# initialize listbox   
$listbox = new-object windows.forms.listbox
$listbox.Width = 500
$listbox.Location = New-Object System.Drawing.Size(10,10)

# initialize textbox
$textbox = new-object system.windows.forms.textbox
$textbox.Location = New-Object System.Drawing.Size(10,120)
$textbox.Multiline = $true
$textbox.Width = 500
$textbox.Height = 200
$textbox.ScrollBars = "Vertical"
$textbox.Visible  = $false

$index = -1

$form.add_keydown({if ($_.KeyCode -eq "Return")
    {
        $index = $listbox.selectedindex
        if ($index -gt -1)
        {
            #--------------start one line------------#
            $textbox.text = $feeds[$index] |
            Select-Object Description |
            ConvertTo-Html
            #--------------end one line--------------#
            $textbox.Visible  = $true
        }
    }
})

# Fill teh listbox with the RSS titles
foreach ($feed in $feeds)
{
    $listbox.items.add($feed.title)
}

# Add alle objects to the form
$form.controls.Add($listbox)
$form.Controls.Add($textbox)
$form.ShowDialog()
Tags Tags: ,
Categories: PowerShell
Posted By: Richard
Last Edit: 20 Jul 2009 @ 06 28 PM

EmailPermalinkComments (0)

 

Here is a small script for something you could do with any other tool but is was fun building it in Powershell. I needed to scan a few subnets in our infrastructure. I know there are tools who can do this task but I thought why not use powershell.

This is what I made of it. The function pinger is straight forward. It does a ping and checks if the output of the pinger function is success. If so the host is up and running otherwise the host is down.

I ran in to a small problem when I wanted to export the output of this powershell script to Microsoft Excel because, I don´t live in the US, my local settings are NL and not en-US. If you use the code found on the Internet  you get a error message like this one.

Exception calling "Add" with "0" argument(s): "Old format or invalid
type library. (Exception from HRESULT: 0×80028018
(TYPE_E_INVDATAREAD))"

 

The code below is unusable if you don’t have you local settings set to
en-US.

$a = New-Object -comobject Excel.Application

$a.Visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "A value in cell A1."
$b.SaveAs("C:\Scripts\Test.xls")

$a.Quit()

 

The code used in my code fixes this by using the invoker function  to force the use of en-US in the Excel workbook. I found this invoker function on the Internet but I don’t know who wrote it so thanks to mister/miss X.

function pinger
{
    param($ip)
    $ping = New-Object System.Net.NetworkInformation.Ping
    $alive = $ping.send($ip)
    if ($alive.Status -eq "Success")
        {
            $out = $ip  + ", Is alive"
            return $out
        }
    else
        {
             $out = $ip  + ", Is dead"
            return $out
        }
}

function Invoke([object]$m, [string]$method, $parameters)
{
    $ciUS = [System.Globalization.CultureInfo]'en-US'
    #----------one line start-------------------------- 
    $m.PSBase.GetType().InvokeMember(
    $method, [Reflection.BindingFlags]::InvokeMethod,
    $null, $m, $parameters,$ciUS)
    #----------one line end----------------------------
} 

#----------------User settings-------------------------
$count = 1
$Max = 10
$ipbase="10.10.10."
#------------------------------------------------------

$objExcel = New-object -com Excel.Application
$objExcel.visible = $True
$objWorkbook = Invoke $objExcel.Workbooks Add
$objWorksheet = $objWorkbook.Worksheets.Item(1)

$objWorksheet.Cells.Item($count,1).Formulalocal = "IP number"
$objWorksheet.Cells.Item($count,2).Formulalocal = "State"

while($count -le $max)
{
    $out=pinger $ipbase$count
    $parts=$out.Split(",")
    $objWorksheet.Cells.Item($count+1,1).Formulalocal = $parts[0]
    $objWorksheet.Cells.Item($count+1,2).Formulalocal = $parts[1]
    $count++
}

Invoke $objWorkbook SaveAs "C:\Ping states.xlsx" > $null
Invoke $objWorkbook Close 0 > $null
$objExcel.Quit()
Tags Tags: ,
Categories: PowerShell
Posted By: Richard
Last Edit: 13 Jul 2009 @ 07 44 PM

EmailPermalinkComments (0)

 13 Jul 2009 @ 10:52 AM 

Found this Powershell toolbar trough a co-worker.

image

This Powershell toolbar gives you quick access to Powershell resources like:

  • Powershell books
  • Blogs about powershell
  • Powershell training programs
  • Powershell Forums

You can download the toolbar here!

Tags Tags: ,
Categories: PowerShell
Posted By: Richard
Last Edit: 02 Sep 2009 @ 08 47 AM

EmailPermalinkComments (0)

 22 Aug 2008 @ 11:06 AM 

We are merging two Active Directories to one and Exchange 2003 was one the components that needed to be migrated to the new Active Directory. The old Exchange 2003 had Email addresses based on the login credentials of the users. In the new Active Directory user login credentials differ from the local part of the email address. So user name and email address where no longer related.

itsme

The problem we ran into was that when logging on to your Exchange account, using IMAP or POP3, you need to supply your user credentials and the alias that is connected your account. Your login looks something like this: AD\Username\Alias. If you try to logon with just your username you get the error USER UNKNOWN.

Thanks to my colleague Arno Beverwijk for reading the documentation…

So we made the Alias match the userlogonname so we didn’t have to bother our users with special logon procedures.

A real case of RTFM…….. It’s not a BUG it’s a FEAUTURE.

Tags Tags: , ,
Categories: Exchange2003, Microsoft, email
Posted By: Richard
Last Edit: 11 Jul 2009 @ 12 37 PM

EmailPermalinkComments (0)

 10 Jul 2008 @ 9:32 AM 

 

officialpenguin[1]   powershell

Marcus Nasarek has written an article for Linux-magazine about BASH and MS PowerShell. It’s nice to read because he took the time to get to know MS Powershell.

Read at source: Linux-magazine

Tags Tags: ,
Categories: Bash, Linux, Microsoft, PowerShell
Posted By: Richard
Last Edit: 10 Jul 2009 @ 07 30 PM

EmailPermalinkComments (0)


It took me some time to figure this one out. After installing SP3 on my Windows XP virtual machine I was no longer able to update my Windows with Microsoft update.

After some debugging I found out that Windows installer was the problem. All windows updates failed directly after installation.

itsme

The message I received was: the update or the updates were not installed successfully.

What I did to fix the problem was remove SP3 for Windows XP installed Windows installer 3.1, applied all available updates and last I reinstalled SP3 for Windows XP.

After I fixed it on my Virtual Machine I found this article on the support page of Microsoft but by that time I knew what to look for so… maybe I can save somebody else his or her time by giving you this article up front.

This article has a more simple solution to the problem. This article Explains how to register a DLL that is not registered correctly on a Windows XP SP0 machine where you install SP3. The steps

net stop wuauserv

For x86
regsvr32 %windir%\system32\wups2.dll

for x64
regsvr32 %windir%\syswow64\wups2.dll

net start wuauserv

Tags Categories: Microsoft, Windows XP Posted By: Richard
Last Edit: 13 Jul 2009 @ 08 13 AM

EmailPermalinkComments (0)

 01 Jul 2008 @ 8:46 PM 

 

We all have our weak moments and do stupid things. Just like I did with our virtual center database transaction log. I did not set a maximum growth limit to which the transaction log could grow and so it ran out of disc space. And our Virtual Center server stop running because of it. So I needed to trash the transaction log and fast. I made this little SQL script that can be run with SQL Query Analyzer.

itsme

 

The very simpel solution to this problem:

USE [YouVirtualCenterDB]

BACKUP LOG [YouVirtualCenterDB] WITH TRUNCATE_ONLY

DBCC SHRINKFILE([YouVirtualCenterDB]_log,2)

Remeber this will trash your transaction log. It will not be backuped to disc it will be written to dev NULL. This script is only to be used if your sure you don’t need the transaction log or you need the database running again in a very short time and there is no other way.

Hope it helps some of you.

Tags Tags: , ,
Categories: Microsoft, SQL server, VMWare
Posted By: Richard
Last Edit: 10 Jul 2009 @ 07 32 PM

EmailPermalinkComments (0)

 30 Jun 2008 @ 6:54 PM 

mslogo-1

I personally think that Powershell is one of the best initiatives Microsoft has launched in the last few years. But anyone who is hoping to start with Powershell V2 soon will be disappointed after reading this post.

This post of the PowershellTeam gives us an estimate of when Powershell V2 is to be released. Only no specific date is mentioned because that information is not to be released at this time. But from the post I get the impression that its no sooner than mid 2009 Powershell V2 is to be released.

And now I’m a bit sad because I’m a big Powershell enthusiast.

Tags Tags:
Categories: Microsoft, PowerShell
Posted By: Richard
Last Edit: 30 Jun 2008 @ 09 43 PM

EmailPermalinkComments (0)




\/ More Options ...
Change Theme...
  • Users » 62
  • Posts/Pages » 19
  • Comments » 1
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About me



    No Child Pages.