DRIVE EFFICIENCY THROUGH AUTOMATED IT.
SAVE COST THROUGH CONSOLIDATION OF IT.
WANT TO KNOW MORE ABOUT STRATEGIC CONSULTING CLICK HERE.
MICROSOFT / RISUAL HYPER-V CLOUD EVENT 22ND MARCH 2011 CLICKHERE.

Archive

Author Archive

PowerShell string manipulation

August 18th, 2010 Joe Comments off

Whilst trying to automate some reporting automation and analysis , I overcome a requirement to reformat a csv ( loosest sense of the term) so that PowerShell will process it.  The following is a useful demonstration of how to manipulate text data and reformat it, also the use of regex (Regular Expression) in PowerShell to identify the current days file.

This has been tested against PowerShell 1.0 on Microsoft Windows Server 2003

##
# A csv Files report is created but you are unable to load it as a csv File due to irregular  formatting of the report.
# this will serve as a good example of string manipulation.
#
# Issues with csv file
# remove top 6 lines, header information not required.
# headers contain , but are not quoted, so you now have more columns than data
# trailing , stop PowerShell loading csv as you can not have a blank header
# the data is includes a % sign.  this then stop it being a number when imported into SQL / Excel
#———————————————————–
#
#
$tmpfile    = “temp.csv”
$mydat        = (get-date ((get-date).adddays(-1))-uformat “%Y%m%d”)    # get yesterdays date in the correct format
$filter        = [regex] “^Daily-View.*$mydat[0-9]{6}.csv$”            # Use regex to find today’s file
$csvfile    = Get-ChildItem -Path “c:Joetest*.csv” | Where-Object {$_.Name -match $filter} # return 1 filename

#              use PowerShell to drop the first 6 lines of unwanted text at the beginning of the file
#

$csvContent = get-content $csvfile

$csvContent | select -last ($csvContent.count -6) | Out-File $tmpfile

#             replace “, %”   with  ” %” 
#
$csvContent = “”
$csvContent = get-content $tmpfile
$csvContent[0] = $csvContent[0].replace(“, %”,” %”)

#             remove trailing , on header line
#
$csvContent[0] = $csvContent[0].substring(0,($csvContent[0].length)-1)     # remove the last char on the line

#             remove all the “%” signs from the data  ( but not the header) 
#

$counter = 0
foreach ($line in $csvContent)
{
    if ($counter -ne 0)     # skip the header line
    {
    $csvContent[$counter] =$csvContent[$counter].replace(“%”,”")
    }
$counter++
}

#            output the plain txt file
#
$csvContent | out-file $tmpfile

#             now you can import the file as a csv with no errors
#
$csvdata = import-csv $tmpfile
$csvdata

#        ————————————–
#         now you can do stuff with the data here
#        ————————————–

#         Remove old temp file
#
if (test-path $tmpfile)
    {
        remove-item -path $tmpfile -force
    }

Categories: Uncategorized Tags: ,

Oracle Virtual box 3.2.6 duplicate UUID Issue when copying disks files

August 9th, 2010 Joe Comments off

I have built a new VM recently using VirtualBox and needed to use it as my base image, I stop the VM and copied the disk files to a new name and location. I then tried to create a new VM and attach the copied disk, only to get the following error

“Failed to open the hard disk”

“Cannot register the hard disk ‘testdisk2.vdi’ with UUID {UUID} because a disk  ‘Testdisk1.vdi’ with {UUID} already exists in the media registry””

image

The solution is to use the command line tool to clone the drive as follows:

open a command window (start > Run > cmd)

cd C:Program FilesOracleVirtualBox             (move to the program files folder)

VBoxManage.exe clonevdi “testdisk1.vdi” “f:VirtualBoxtestdisk2.vdi”

This will clone the drive to the new file and location which you can then use. This will need to be done for each subsequent copy.

Categories: Uncategorized Tags:

Windows 2008 R2 activation problem ( 0x8004FE2F , 0x8007232B on x64 servers)

July 22nd, 2010 Joe Comments off

Like the 100′s of times before,  you install Windows 2008 R2 on to a server , try activating it ,and get the error :-

0x8007232B – DNS name does not exist

then you remember to set the proxy settings.. you open internet explorer and change the proxy settings , you can now browse the internet,   and try activation again

but this time it still fails… that’s not supposed to happen, as you can access the web.  (also phone activation completely failed at this point too.)

This time it fails with code 0x8004FE2F

You find other blogs  on the internet, which suggest that its your proxy settings that have not been set,  and they are right but what they don’t tell you is specifically its Internet Explorer (64 bit) you need to set the proxy for. I had inadvertently set the IE (32 bit) settings previously.

Happy installations.