<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>missmiis &#187; Excel</title>
	<atom:link href="http://www.wapshere.com/missmiis/category/excel/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wapshere.com/missmiis</link>
	<description>Adventures in identity management</description>
	<lastBuildDate>Sun, 05 Sep 2010 06:41:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Repairing links in Excel documents</title>
		<link>http://www.wapshere.com/missmiis/repairing-links-in-excel-documents</link>
		<comments>http://www.wapshere.com/missmiis/repairing-links-in-excel-documents#comments</comments>
		<pubDate>Fri, 14 Nov 2008 09:39:44 +0000</pubDate>
		<dc:creator>Carol</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.wapshere.com/missmiis/?p=255</guid>
		<description><![CDATA[Another off-topic post today, because lately it&#8217;s all been migrations &#8211; Exchange migrations, data migrations, printer migrations&#8230;. I think I might have to rename this blog Miss Migrations! As part of an enourmous data migration involving server name and drive letter changes, I was tasked with repairing links in thousands of Excel spreadsheets. We trialled [...]]]></description>
			<content:encoded><![CDATA[<p>Another off-topic post today, because lately it&#8217;s all been migrations &#8211; Exchange migrations, data migrations, printer migrations&#8230;. I think I might have to rename this blog Miss Migrations!</p>
<p>As part of an enourmous data migration involving server name and drive letter changes, I was tasked with repairing links in thousands of Excel spreadsheets. We trialled a commercial link fixing product but abandonned it because of its unfriendly habit of making you start right back from the beginning whenever it crashed, which it did regularly.</p>
<p>I wrote a few vbscripts and, while definitely slower and not without their own problems (mostly caused by the Excel docs themselves, and their multiplicitous configurations, macros and protective devices), I could at least control my file lists, and make modifications as needed.</p>
<p><span id="more-255"></span></p>
<h3>The scripts</h3>
<p>The following scripts can be used to first search for, and then repair links in Excel spreadsheets. The links can be either source links (where source data is imported from another file &#8211; see Edit-Links in Excel) or hyperlinks in spreadsheet cells.</p>
<p>These scripts are <em>not fast</em>. However you can run multiple instances at a time so, if you have a lot to get through, break it down into subfolders, rather than hitting a whole file system at once.</p>
<table border="0">
<tbody>
<tr>
<td><strong>Script</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td><a href="http://www.wapshere.com/missmiis/?page_id=257">find_links_folder.vbs</a></td>
<td>Search a folder and subfolders for Excel documents with sourcelinks and hyperlinks</td>
</tr>
<tr>
<td><a href="http://www.wapshere.com/missmiis/?page_id=260">find_links_filelist.vbs</a></td>
<td>Search a list of Excel documents for sourcelinks and hyperlinks</td>
</tr>
<tr>
<td><a href="http://www.wapshere.com/missmiis/?page_id=265">change_sourcelinks.vbs</a></td>
<td>Change sourcelinks in a list of Excel documents using string replace</td>
</tr>
<tr>
<td><a href="http://www.wapshere.com/missmiis/?page_id=263">change_hyperlinks.vbs</a></td>
<td>Change hyperlinks in a list of Excel documents using string replace</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.wapshere.com/missmiis/repairing-links-in-excel-documents/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>powershell: Retrieving data from Excel</title>
		<link>http://www.wapshere.com/missmiis/powershell-retrieving-data-from-excel</link>
		<comments>http://www.wapshere.com/missmiis/powershell-retrieving-data-from-excel#comments</comments>
		<pubDate>Sat, 04 Oct 2008 07:36:22 +0000</pubDate>
		<dc:creator>Carol</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.wapshere.com/missmiis/?p=194</guid>
		<description><![CDATA[I would love nothing better than to do one ILM project after another, but it doesn&#8217;t always pan out like that, so now I&#8217;m back to the bread-and-butter work of server installations, email migrations and security audits. Still, it&#8217;s giving me an opportunity to get my powershell skills up to date. This post, after some blurb, includes a [...]]]></description>
			<content:encoded><![CDATA[<p>I would love nothing better than to do one ILM project after another, but it doesn&#8217;t always pan out like that, so now I&#8217;m back to the bread-and-butter work of server installations, email migrations and security audits. Still, it&#8217;s giving me an opportunity to get my powershell skills up to date.</p>
<p>This post, after some blurb, includes a script I wrote to extract data from an Excel spreadsheet. At this point I don&#8217;t think I&#8217;ll actually use it, but it was an interesting exercise.</p>
<p><span id="more-194"></span></p>
<p>Like most people, I find it frustrating learning new methods when the old way would be much quicker. I&#8217;ve been sticking firmly to vbscript, but Exchange 2007 has forced me into this alleged shell of power.</p>
<p>Some of my frustration has, I think, been perfectly valid. Just try setting file system ACLs. Set-acl just does not do enough - for instance you can&#8217;t block inheritance. You can call cacls from powershell, but just try using the &#8220;&lt;&#8221; to pipe in the &#8220;y&#8221; character and suppress the prompting &#8211; powershell politely informs you that it doesn&#8217;t support &#8220;&lt;&#8221; redirection. Big raspberry.</p>
<p>Other things, however, it does do very well indeed. I love the handling of CSV files. This command</p>
<pre>import-csv file.csv | foreach { ... }</pre>
<p>is both elegant and really, really useful.</p>
<p>But on to the subject of this post. Similar to a <a href="http://www.wapshere.com/missmiis/?p=84">vbscript I wrote</a> for another customer, I was asked to get some info into AD based on an excel spreadsheet. Time to figure out how to do this in powershell.</p>
<p>First off, I ran into an <a href="http://support.microsoft.com/kb/320369" target="_blank">irritating bug</a> based on the culture settings. If you are using english Excel you have to set your culture to English<strong>(US)</strong> to be able to interact with Excel from powershell. Another big raspberry to Microsoft for that one!</p>
<p>Next I struggled with the usual lack of documentation on the COM object properties and methods, and the fact that they don&#8217;t seem to work the same in powershell as vbscript. For instance in vbscript I could retrieve the top-left cell value by doing this:</p>
<pre>objExcel.Cells(1,1).Value</pre>
<p>but in powershell I was told that method didn&#8217;t exist, and the only way I could get at the data was by instatiating a worksheet object and doing this:</p>
<pre>$objSheet.Cells.Item(1,1).Text</pre>
<p>Why the difference? I really don&#8217;t know.</p>
<p>The script below was more an exercise that anything else. What with the culture bug and some other considerations I think I&#8217;ll end up using a CSV approach to the actual task, but I think this is worth posting just to show how it&#8217;s done.</p>
<pre># import_excel.ps1
# Retrieves data from a mult-worksheet Excel file
# and writes to the console in csv format.</pre>
<pre>$strExcelFile = "MySpreadsheet.xls"</pre>
<pre>$objExcel = New-Object -comobject Excel.Application
$objWorkbook = $objExcel.Workbooks.Open($strExcelFile)</pre>
<pre>write-host "Numer of worksheets: " $objWorkbook.Sheets.Count</pre>
<pre>$row = 1
$col = 1
$sheet = 1</pre>
<pre>while ($sheet -le $objWorkbook.Sheets.Count)
{
  $objSheet = $objWorkbook.Sheets.Item($sheet)
  write-Host "Worksheet: " $objSheet.Name</pre>
<pre>  #Count number of columns in row 1 until first blank
  $numCols = 0
  while ($objSheet.Cells.Item(1,$col).Text -ne "")
  { $col += 1 ; $numCols += 1 }
  $col = 1</pre>
<pre>  #Iterate through rows, stopping at the first blank in col 1
  while ($objSheet.Cells.Item($row,1).Text -ne "")
  {
    $strLine = ""
    while ($col -le $numCols)
      {
         if ($col -eq 1) {$strLine = $objSheet.Cells.Item($row,$col).Text}
         else {$strLine = $strLine + "," + $objSheet.Cells.Item($row,$col).Text}
         $col += 1
      }
    write-host $strLine
    $row += 1
    $col = 1
  }
 
  $sheet += 1
  $row = 1
  $col = 1
  write-host
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.wapshere.com/missmiis/powershell-retrieving-data-from-excel/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating AD attributes from an Excel spreadsheet</title>
		<link>http://www.wapshere.com/missmiis/updating-ad-attributes-from-an-excel-spreadsheet</link>
		<comments>http://www.wapshere.com/missmiis/updating-ad-attributes-from-an-excel-spreadsheet#comments</comments>
		<pubDate>Wed, 19 Dec 2007 10:22:22 +0000</pubDate>
		<dc:creator>Carol</dc:creator>
				<category><![CDATA[AD]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.wapshere.com/missmiis/?p=84</guid>
		<description><![CDATA[You don&#8217;t always have access to a proper IdM system. At the moment I&#8217;m at an organisation which still uses the old, manual ways of updating AD. I was asked if I knew an easy way to update the mobile phone numbers of a list of users, the data having been sent to Helpdesk in [...]]]></description>
			<content:encoded><![CDATA[<p>You don&#8217;t always have access to a proper IdM system. At the moment I&#8217;m at an organisation which still uses the old, manual ways of updating AD. I was asked if I knew an easy way to update the mobile phone numbers of a list of users, the data having been sent to Helpdesk in a spreadsheet. I knew that a long list of departments were shortly to be changed as well, so I figured I&#8217;d make a general solution, where you could also specify the attribute name in the spreadsheet.</p>
<p>I actually ended up writing the script twice.</p>
<p><span id="more-84"></span></p>
<ol>
<li>First I used DNs as the search criteria, which makes the script quite simple, and also means it will work with any object type. You can see that script <a href="http://www.wapshere.com/missmiis/?page_id=81" target="_blank">here</a>.</li>
<li>Then, after seeing that the source spreadsheet contained usernames rather than DNs, I modified the script to use the CN instead. The restriction is that now the script only works with user objects (though there&#8217;s actually no reason why you couldn&#8217;t make a column for the object type in the spreadsheet as well). That script is <a href="http://www.wapshere.com/missmiis/?page_id=83" target="_blank">here</a>.</li>
</ol>
<p>It needs to be noted that these scripts should only be used for updating single-valued attributes. I have included <em>no back-out</em> &#8211; so if you have the wrong data in your spreadsheet I accept no responsibility for you putting rubbish in your AD.</p>
<p>You also need to make sure your spreadsheet is tidy, with even column lengths, and no blank row in the middle (the script stops at the first blank cell).</p>
<p>For the CN script your spreadsheet should look something like this:</p>
<table border="1">
<tbody>
<tr>
<td>jbloggs</td>
<td>department</td>
<td>IT Helpdesk</td>
</tr>
<tr>
<td>jbloggs</td>
<td>mobile</td>
<td>0123456789</td>
</tr>
<tr>
<td>hzhen</td>
<td>description</td>
<td>Administrative Assistant</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.wapshere.com/missmiis/updating-ad-attributes-from-an-excel-spreadsheet/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
