Winfred Like a boss.

  • Skip to content
  • Jump to main navigation and login

Nav view search

Navigation

  • About Winfred

Search

You are here: Home

Technical References

  • All Tech References
  • Arduino
  • PowerShell
  • Windows Server

This Site

  • Home
  • Site Map
  • Login

Login Form

  • Forgot your password?
  • Forgot your username?

MediaInfo and PowerShell

It is possible to use MediaInfo in PowerShell, by specifying the parameter --Output=XML and loading this into a XML Object, like this:

        $xmldata = new-object "System.Xml.XmlDocument"
        $xmldata.LoadXml((Invoke-Expression "$Executable --Output=XML `"$MovieFile`""))

Full code after the break:

Read more: MediaInfo and PowerShell

Disable IP Binding for the HP System Management Homepage

If IP binding is enabled for HP System Management Homepage (which is used to manage HP Proliant Servers), it can by default only be accessed from the server itself, because it binds to 127.0.0.1. In order to disable this, I've written a PowerShell function that can disable IP binding remotely and for multiple servers. It uses xmlobjects and get-service.

Read more: Disable IP Binding for the HP System Management Homepage

Multiple simultaneous defrag jobs with PowerShell

There is some code out there that shows how to do defrag hard disks using WMI. Basically:

[string]$query = 'Select * from Win32_Volume where DriveType = 3'
$volumes = Get-WmiObject -Query $query -ComputerName $ComputerName
$result = ($volume.Defrag($force)).ReturnValue

Of course, this can take quite some time when running this against a list of servers, since .Defrag() does not start on the second computer, until it completed the first. You can avoid this (assuming you have PowerShell 2), by using start job:

start-job -Name $ComputerName `
    -initializationScript {ipmo defrag} `
    -scriptblock {Param ($ComputerName) Start-CustomDefrag $ComputerName} `
    -ArgumentList $ComputerName

Full code after the break.

Read more: Multiple simultaneous defrag jobs with PowerShell

Wikipedia Image Scraper

I've written a "Wikipedia Featured Pictures" scraper in PowerShell, using DotNetWikiBot. It downloads all 2500+ featured images (featured images are the images that are shown on the front page of Wikipedia).
 
$LocalFolderToSaveTo = "C:\DownloadLocation"
[System.Reflection.Assembly]::LoadFile("D:\Documents\WindowsPowerShell\test\dotnetwikibot\DotNetWikiBot.dll")
$EnWiki = new-object DotNetWikiBot.Site("http://en.wikipedia.org", "WikipediaUserName", "WikipediaPassword") 
$PageList = new-object DotNetWikiBot.PageList($enWiki);
$PageList.FillFromCategory("Featured pictures")
$ImageExts = ".jpg", ".png", ".jpeg"
Foreach($Page in $PageList.pages)
{
 if(($ImageExts -eq $Page.Title.substring($Page.Title.length - 4, 4)) -and (!($Page.Title.startswith("File talk"))) )
 {
 $DownloadTo = $Null
 $RenamedPage = $Page.Title.replace("File:", "")
 $RenamedPage = $RenamedPage.replace("`"", "") # "
 $RenamedPage = $RenamedPage.replace("`'", "")
 $DownloadTo = join-path $LocalFolderToSaveTo ($RenamedPage)
 $page.DownloadImage($DownloadTo)
 Start-Sleep 1 #Build in delay to prevent hammering and/or Ban. 
 }
}

BMW - Windows XP startup - shutdown

On a beautiful day I was thinking, wouldn't it be cool if other devices also had start-up and shutdown tunes, just like your computer? For example, your TV, your car or your motorcycle? Since I was looking for a simple project to that uses an Arduino microcontroller, I decided to add the Windows XP Startup and Shutdown sounds to my BMW F650.

Read more: BMW - Windows XP startup - shutdown

Access denied error when resizing a HTA

When I resized a HTA with the following code:

 Sub Window_onLoad
     window.resizeTo 500,200
End Sub

I came across the following error:

Access Denied
Code: 0
Do you want to continue running scripts on this page?

This was due to a timing issue when loading the file. The Window_onLoad tries to change a property of the HTA, while the HTA is not completely loaded yet. You can solve this problem by adding a short timeout like this:

Sub Window_onLoad
Window.SetTimeout "Window.ResizeTo 500, 200", 500
End Sub

The last "500" here is the time it waits before executing the code.

Image of the error message:

VB Script that changes the CDROM drive letter

'
'    Script creates a local file that gets called by Diskpart to change the CDROM drive to Z:
'
'    

Read more: VB Script that changes the CDROM drive letter

VB Script that creates shortcuts on remote machines

'
'
'This script creates a drive mapping to C$ of a list of servers, checks if a certain file exists and creates a
'shortcut in the startup menu to that file, then removes the mapping.
'
'
'

Read more: VB Script that creates shortcuts on remote machines

Bubble Sort in VBS

This is the code required to sort an array in alphabetical order (you need UCase to convert the lower case to upper case, because VB sorts on ASCII value and the value of upper case characters is higher than that of lower case characters.

For i = (UBound(arrNames) - 1) to 0 Step -1
For j= 0 to i
If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
strHolder = arrNames(j+1)
arrNames(j+1) = arrNames(j)
arrNames(j) = strHolder
End If
Next
Next

Bubble sort is not the most efficient way for sorting and should not be used on large arrays.

For more information on bubble sort: http://en.wikipedia.org/wiki/Bubble_sort

Installing a Persistent iSCSI initiator on Hyper-V 2008 R2

Because Hyper-V Server 2008 R2 does not have a GUI, all tasks needed to set up an iSCSI initiator need to be done either remotely or from the command prompt.


The iSCSI initiator service needs to start automatically(this can also be done remotely by opening a MMC, adding the services snapin and connecting to the Hyper-V Server): sc config msiscsi start= auto

Start the service (most likely the SC command will already trigger the starting of the service): net start msiscsi

Connect to the iSCSI target Server: iscsicli QAddTargetPortal 10.0.0.1

Now get a list of iSCSI targets: iscsicli ListTargets

Next, copy the target you want and run this command (replace the iqn with your own): iscsicli persistentlogintarget iqn.1991-05.com.something:server-vms-target T * * * * * * * * * * * * * * * 0

Now reboot: shutdown /r /t 10

And verify if the disk is actually mounted. You can do so with either diskpart.exe on the server itself, or you can open an MMC from another computer, add the disk manager snap in and verify visually.

How to add a loopback adapter in Windows Server 2008 Core

How to add a loopback adapter to Windows 2008 server Core:

Find a 2003 server installation disk, x86 or x64 depending on the version you need and navigate to: \SUPPORT\TOOLS\SUPPORT.CAB and extract Devcon.exe.

For a 32 bit version you might be able to simply use the downloadable version of devcon, for 2008 x64, you definitely need to use devcon from support.cab on a 64 bit Windows 2003 server installation disk (I only tested this for the x64 version).

Then on the command line type:

C:\temp>devcon.exe install c:\windows\inf\netloop.inf *MSLOOP

 If you did  it right, you will see this:

Device node created. Install is complete when drivers are updated...
Updating drivers for *MSLOOP from c:\windows\inf\netloop.inf.
Drivers updated successfully.

And ipconfig /all will show this:

 Ethernet adapter Local Area Connection 4:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Loopback Adapter
   Physical Address. . . . . . . . . : 02-00-4C-4F-4F-50
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::590d:2eb0:55c9:3959%20(Preferred)
   Autoconfiguration IPv4 Address. . : 169.254.57.89(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :
   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   NetBIOS over Tcpip. . . . . . . . : Enabled

 If you used the wrong version of devcon you will get the following error:

 devcon.exe failed.

Page 1 of 2

  • Start
  • Prev
  • 1
  • 2
  • Next
  • End

Powered by Joomla!®