I wrote a script to read a list of folder objects into an xml file showing the properties for the folder. It also creates another xml file at a later point in time. After the delta xml file is created, I import both xml files and compare them based on the folder name to display which folders have been deleted or removed and save the results in html format to a file for viewing. Everything works well, but I want to replace some of the values in the results. The compare-object cmd-let lets me display some attributes, but tells what side the change was on by putting => for a folder added in the delta file or <= for a folder removed in the delta file. I really would like to replace the column name of SideIndicator and the replace the => or <= values with something more intuitive. I played around with useing -Replace {$_ $original, $newvalue} type method. I found guidance on Hey Scripting Guy blog and some other examples around, but none seemed to do what I want. What is the best way to approach this? Currently I'm not storing the compared results, just formatting and converting to HTML. Any advice is appreciated. I can post 开发者_开发技巧the code if needed, but it is about 60 lines long and I'm really looking for the best way to accomplish this, not neccesarily someone to write the code.
Thanks!
If you just want to replace column names in the output display, you can create a custom table:
http://gallery.technet.microsoft.com/scriptcenter/ed188912-1a20-4be9-ae4f-8ac46cf2aae4
That is one approach, but I ended up modifying the html report by doing the following:
(Get-Content $WorkingDirectory\FolderAudit_$UseDateTime.htm) |
Foreach-Object {$_ -replace "SideIndicator", "Change Status"} |
Set-Content $WorkingDirectory\FolderAudit_$UseDateTime.htm
(Get-Content $WorkingDirectory\FolderAudit_$UseDateTime.htm) |
Foreach-Object {$_ -replace "=>", "New"} |
Set-Content $WorkingDirectory\FolderAudit_$UseDateTime.htm
(Get-Content $WorkingDirectory\FolderAudit_$UseDateTime.htm) |
Foreach-Object {$_ -replace "<=", "Removed"} |
Set-Content $WorkingDirectory\FolderAudit_$UseDateTime.htm
It didn't seem to work well as one statement that replaced the three different pieces I was looking for. Eventually I'll play around with it and streamline it some, but for now it does what I want.
精彩评论