Bogiecom.com
  • About
  • Magento
  • Sitecore
  • WordPress

Category Archives: Powershell

Recursive File Count with Powershell and Linux Shell

Posted on January 5, 2013 by bc-admin

Today, I needed a quick count of all of the files in Magento in order to set the “apc.num_files hint=xxx” in APC. Since all of the source files were on my Windows machine already, I started with Powershell.

Powershell (Windows)

1
(gci .\magento -recurse | Where-Object {-not ($_.PSsContainer)}).Count

After that, for accuracy sake, I checked on the server as well.

Linux Shell (Ran from inside the directory)

1
find . -type f | wc -l

Posted in Linux, Powershell, Shell Scripting | Leave a comment |

Powershell String Formatting to Html

Posted on August 22, 2012 by bc-admin

Ever had a bunch of rows in a text file that you would like to format as an html table, but don’t want to take as much time formatting all of the tr and td rows.  You can do something like this:

Say you have a comma-delimited text file with some rows like:

1
foo1,foo2,foo3

And you want to output them as html or something, you can do something like this:

1
2
Get-Content .\thetext.txt | %{ $data = $_.split(","); Write-Output "
$($data[0]) $($data[1]) $($data[2])" } > text-output.html

You should get something like this:

1
foo1 foo2 foo3

It certainly speeds up some tedious formatting of some static or maybe dynamic data.

Posted in Comma-Delimited, Files, HTML, Powershell | Leave a comment |

Changing SQL Schema in Mysql Dump Files using Powershell

Posted on June 14, 2012 by bc-admin

Quick way to change the schema name in all mysql dump files in a directory using Powershell. Or you could just use it to change a string in files of particular type in a directory

1
2
C:\Users\SloshDev> foreach($f in gci("*.sql")){
              (Get-Content $f.fullname) | %{ $_ -replace "magento_1_9","magento_1_12" } | Set-Content $f.fullname }

Here’s how I changed the default character set from latin1 to utf8. May not want to use if different columns use different character sets.

1
2
3
C:\Users\SloshDev> foreach($f in gci("*.sql")){
      (Get-Content $f.fullname) | %{ $_ -replace "latin1","utf8" } | Set-Content $f.fullname
     }

Posted in Dump Files, MySQL, Powershell | Leave a comment |

Find String in Files with Given Extension Using PowerShell

Posted on May 10, 2012 by bc-admin

Steve Smith, Founder of NimblePros, Speaker, Author, and Software Craftsman. Microsoft MVP and Regional Director. Gives a great example on Recursively locating files with particular text strings and a given extension in PowerShell.
Find String in Files with Given Extension Using PowerShell

Posted in Files, Powershell, Strings | Leave a comment |

Imagick Powershell Resize Images In Folder

Posted on November 18, 2011 by bc-admin

Here’s a quick one-liner to re-size photos if you have Imagick installed using PowerShell. It also renames the files with the dimensions specified:

1
2
PS C:\Users\SloshDev> gci("*.jpg") |
      %{convert  $_.FullName -resize 500x500 $_.Name -replace '\.jpg$','-500x500.jpg'}

Ultimately ended up with this to rename the file based on the actual dimensions of the file in the end:

1
2
PS C:\Users\SloshDev> gci("*.jpg") |
   %{convert $_.FullName -resize 500x500 -set filename:area '%wx%h' ($destination + ($_.Name.Trim("\.jpg") + "-%[filename:area].jpg"))}

This is great if you want to do this within the file itself, however if you need to specify dimensions, source and destination directories, and specific image file extensions you could use a script like this:

1
2
3
4
5
6
7
$source = 'C:\User\SloshDev\My Pictures\'
     $destination = 'C:\User\SloshDev\My Pictures\500's\'
     $ext = "jpg"
     $size = "500x500"
     #Resize Images
      gci("$source*.$ext") |
        %{convert $_.FullName -resize $size -set filename:area '%wx%h' ($destination + ($_.Name.Trim("\.$ext") + "-%[filename:area]." + $ext))}

Posted in Image Resizing, Imagick, Powershell | Leave a comment |

Append Extension to All Files in Directory

Posted on November 11, 2011 by bc-admin

IIS 6.0 did not save configuration files with “.xml” extension automatically. So I needed to add the .xml to the files. So this is what I did:

1
PS C:\_old-IIS-site-configurations> Get-ChildItem *.com | Rename-Item -NewName { $_.Name + ".xml"; }

Nice, quick one-liner to quickly eliminate what would be a pain otherwise.

Posted in Powershell, Rename-Item | Leave a comment |

Miva Merchant Product Attribute Export – Update Pricing with Powershell

Posted on November 9, 2011 by bc-admin

If you’ve ever wanted a tab delimited list of product attributes and prices to update pricing, here’s one way:

Export product attributes through ‘Utilities > Export Data > Export Attributes to XML File’

  1. When exporting choose ‘Replace All Mode
  2. You will have to add a root level element around the xml generated by miva and the file:

    1
    2
    PS C:\>$a = Get-Content .\provide.xml
    PS C:\>Set-Content .\provide.xml -value "<products>",$a,"</products>"      

    Now bring in file as xml:

    1
    PS C:\>$xml = [xml] (Get-Content .\provide.xml)

    Run this command to generate a tab delimited list of Product_Code, Code, & Price

    1
    2
    PS C:\>$xml.Products.ProductAttributeOption_Add |
                   foreach { $_.product_code + "`t" + $_.Price } > .\provide-list.txt

    For more information on Powershell’s xml capabilities and how easy it is to use XML with Powershell visit Powershell XML on Code Project

    .

Posted in Miva Merchant 5.5, Powershell, Updating Product Attributes, XML | Leave a comment |

Pages

  • About
  • Magento
  • Sitecore
  • WordPress

Archives

  • January 2017
  • December 2013
  • November 2013
  • February 2013
  • January 2013
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • November 2011
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • September 2009

Categories

  • .NET
  • Air Force
  • Apache Configuration
  • Bash
  • C#
  • Comma-Delimited
  • Custom Field Validator
  • Date Format
  • Dump Files
  • Files
  • Grep
  • Grooveshark
  • HTML
  • Image Resizing
  • Imagick
  • Integration
  • jQuery
  • Konami Code
  • Linux
  • Magento
  • Magento Third Party CMS Integration
  • Mini Shuttle
  • Miva Merchant 5.5
  • MySQL
  • PHP
  • Powershell
  • Regular Expressions
  • Rename-Item
  • Sed
  • Shell Scripting
  • Sitecore
  • Strings
  • Uncategorized
  • Updating Product Attributes
  • Video Games
  • Wordpress
  • X-37
  • XML
  • YUI Konami Event

CyberChimps WordPress Themes

© 2008 - 2016 Bogiecom.com