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

PowerShell Disable Overrides in SCOM

Example on how to enable or disable overrides in SCOM.

Read more: PowerShell Disable Overrides in SCOM

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. 
 }
}

More Articles...

  1. PowerShell Links