Sunday, June 14, 2009

Scripting: Win32_Service – Change Account/Password

When using Win32_Service to change the service account and/or service account password the following needs to be understood.

StartName is an account name and not the name of the service which is Name for internal service short name and DisplayName for the full visible service name.  The account name MUST be specified when changing the password as it appears that both are always validated.  The only time a Null or empty password can be used is when setting the account to LocalService.  All unused arguments in VB or VBScript must be set to Null or you will get an error. 

Note that the account used must be an accessible account either local or AD and must have the "run as a service" permission or you will get an service account not valid error.  The password must be present but does not need to be correct as this is only checked on an account restart.  Restating the service will check the  password and use the new setting.  If you are just setting passwords then you will have a race condition.

It is more normal to create a new account with the new password and reset all services to the new account.  This will guarantee that you DO NOT have a race condition when setting multiple accounts as the old account can keep the old password until all services have been re-provisioned.

uploads/2491/WMIChangeService.vbs.txt

1 Function WMIChangeServiceAccount(sComputer,serviceName, account, password ) 2 Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2") 3 Set colServices = wmi.ExecQuery("Select * From Win32_Service Where Name = '" & serviceName & "'") 4 For Each oService in colServices 5 result = oService.Change(Null ,Null ,Null ,Null ,Null ,Null ,account , password) 6 If result <> 0 Then 7 Select Case result 8 Case 0 : msg = "Success" 9 Case 1 : msg = "Not Supported" 10 Case 2 : msg = "Access Denied" 11 Case 3 : msg = "Dependent Services Running" 12 Case 4 : msg = "Invalid Service Control" 13 Case 5 : msg = "Service Cannot Accept Control" 14 Case 6 : msg = "Service Not Active" 15 Case 7 : msg = "Service Request Timeout" 16 Case 8 : msg = "Unknown Failure" 17 Case 9 : msg = "Path Not Found" 18 Case 10 : msg = "Service Already Running" 19 Case 11 : msg = "Service Database Locked" 20 Case 12 : msg = "Service Dependency Deleted" 21 Case 13 : msg = "Service Dependency Failure" 22 Case 14 : msg = "Service Disabled" 23 Case 15 : msg = "Service Logon Failure" 24 Case 16 : msg = "Service Marked For Deletion" 25 Case 17 : msg = "Service No Thread" 26 Case 18 : msg = "Status Circular Dependency" 27 Case 19 : msg = "Status Duplicate Name" 28 Case 20 : msg = "Status Invalid Name" 29 Case 21 : msg = "Status Invalid Parameter" 30 Case 22 : msg = "Status Invalid Service Account" 31 Case 23 : msg = "Status Service Exists" 32 Case 24 : msg = "Service Already Paused" 33 Case Else : msg = "Not defined" 34 End Select 35 Wscript.StdErr.WriteLine "WMIChangeServiceAccount failed:" & msg 36 End If 37 Next 38 End Function 39 40 WMIChangeServiceAccount ".", "Browser", "domain\account", "newpassword" 41 42

"Browser" is the name of the service.  The display name is "Computer Browser".  These names are not interchangeable.  "Name" required the internal short name of the service.  You can change the code to use "DisplayName" as the filter.

PowerShell is much better for WMI as it can let us view elements quickly at the command line.

gwmi win32_service
will get all of the installed services
gwmi win32_service | select name
will give us all internal service names
gwmi win32_service -filter "name like 'b%'"
will filter all names that have "b" as a first letter.

Try this with vbscript of CMD.  It can be done but takes far longer to accomplish.

Here is the same password change coded in PowerShell:

gwmi win32_service -filter "name like 'bro%'"|%{$_.Change($null,$null,$null,$null,$null,$null,$null,"domain\account","newpw")}

The decode of the result could be added as an "Enum" extension to the PowerShell type system and we could also add a script to the class that would allow a method of "ChangePassword" that would just take a password.

Saturday, March 22, 2008

Copy HTML contents as Text to Clipboard

Periodically it is necessary to copy the contents of an HTML control to another location in text format.  Selecting elements of an HTML page and using the "context" copy will place the contents on the clipboard in two formats; HTML and plain text.

Copy the following to your clipboard and then paste it into two different editors to see how this works:

The quick brown cat jumped over the

lazy dogs back 1234567890 times

while the sly fox

watched.

First paste this into notepad.  Notice no formatting of course.  Now paste into an HTML editor like an Outlook mail message set for HTML format or paste into MS Word.  The formatting is maintained.

Now do the same with the following:

Sub test

    
Dim myint
    
myint = 1
 
End Sub 

In some browsers just selecting this code is a bit of a problem especially if it goes off the visible page.

The following shows how to add a piece of embedded script that will copy the code to the clipboard as plain text.  It will retain it's line spacing and line ending correctly.  This will greatly simplify delivery of code content to users.

The method:

Include the following in the page scripts in any convenient place:

<script language="jscript" type="text/jscript">
<!--
    
function divout(ctl){
       
var code=ctl.innerText;
       
holdtext.innerText=code;
       
Copied = holdtext.createTextRange();
       
Copied.execCommand('Copy');
       
return false;
   
}
-->
</script>

Include a button or hyperlink like the following:

<input type="button" value="Copy To Clipboard" language="jscript"
onclick="divout(mydiv);"/>

Wrap your code display in a DIV and give it an id.  Set the argument to "divout" to the id of your codes DIV.

Include a dummy <textarea></textarea> that is hidden anywhere on teh page.  This is used to store the interim text while formatting and to allow the contents to be easily extracted to teh clipboard.

<textarea id="holdtext" style="display: none">Empty</textarea>

Press here to see it work:

 

This is a patch for the input button issue.

Sunday, March 16, 2008

Dynamically Load Images from a Database to an HTML Page

Copy Code
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>ADODB Stream Writer Image Test</title>

<script language="vbscript" type="text/vbscript">
Dim Source 'as String
Dim Connect 'as ADODB.Connection
Dim f   'As Scripting.File
Dim s   'As New ADODB.Stream
Dim rs  'As ADODB.Recordset
Connect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AdventureWorks;Data Source=.\SQLExpress"
Source = "SELECT * FROM Production.ProductPhoto"


Sub window_onload

   
Set s = CreateObject("ADODB.Stream")
   
Set rs = CreateObject("ADODB.Recordset")
   
   
rs.Open Source, Connect, adOpenForwardOnly
   
GetImage
   
rs.MoveNext

End Sub

Sub ShowButton
   
btn1.style.visibility = "visible"
End Sub

Sub nextimage()
   
   
btn1.style.visibility = "hidden"

   
If Not rs.eof Then
       
GetImage
       
rs.MoveNext
   
Else
       
MsgBox "No more images - resetting to BOF"
       
rs.MoveFirst
   
End If
   
   
window.setTimeout "ShowButton",400,"vbscript"


End Sub

   
Sub GetImage()
       
fName = rs.Fields("LargePhotoFIleName")
       
photo = rs.Fields("LargePhoto")
       
s.Open
   
s.Type = 1 'adTypeBinary
    s.Write photo
   
s.Flush
   
s.SaveToFile fName, 2 'adSaveCreateOverWrite
    s.Close
   
img1.src = fName
   
txt1.Value = fName
   
End Sub

</script>
</head>
<body>
   
<input id="btn1" type="button" value="click" onclick="nextimage"/>
    <
input id="txt1" type="input"/>
    <
br />
    <
br />
    <
img id="img1" />
</
body>
</html>
Technorati tags:

Sunday, November 25, 2007

Back From a Long Vacation

After not posting for quite some time I felt that I should provide a little information on what has happened in case there may be one or more brae individuals who might be monitoring this all but dead blog.

Six months ago I was diagnosed with Lyme disease.  I have apparently had it for more than six years and was becoming progressively more debilitated.  Over those years I was hospitalized repeatedly but told that there was nothing wrong.  After my heart stopped a couple of times I still didn't have a diagnosis.

On each hospitalization I told the doctors that I was certain that I had an infection and I listed all of the symptoms.  They insist6ed I was imagining these things or that I might have a psych problem.  One doctor insisted that my symptoms were symptoms of heroin withdrawal and required that I be tested for drugs.   When the test came back negative he said there was nothing wrong with me and sent me home.

One smart doctor looked at me six months ago and said "I think you have Lyme disease".    I have been on antibiotics now for six months and am just starting to feel more normal.  For many months I could barely stand up.  This disease is one where the cure can be more devastating than the disease when you have had it for as long as I have. I hope I continue to regain my normal unlimited energy level although I don't expect to be "normal" for many more months.  At least I can sit at the keyboard for more than five minutes without nearly passing out.

For the next couple of months I will be playing catch-up wit the technology and forums. Hopefully, I will soon return to blogging on a more regular basis.

Here is a useful starting point or anyone interested in information on Lyme disease.  This is a very useful site to refer your doctor to.  Most doctors are very limited in their knowledge this disease.  older information about Lyme was incorrect and has downplayed it's seriousness.   The most difficult thing about diagnosing Lye is that it can mimic many other diseases and is very hard to get a reliable laboratory test.  Most test that are negative for Lyme are incorrect which is most often the case when the disease has been in the system for a long time.

http://www.lymeinfo.net/index.html

Thursday, May 24, 2007

Script With Class in VBScript

Someone asked me to help with a script and to also give some assistance in how best to use VBScript to accomplish tasks simply and quickly.  I took the opportunity to inject a "Class" that I use frequently to send formatted output to a log file.  This seems to have caused no end of confusion for the poor soul whose burden I was trying to lighten.

The use of classes in VBScript appears to be not well understood.  Consider the following:  You use an object to retrieve WMI information.

Set objWMI = GetObject("winmgmts:...)

The "objWMI" object is an instance of a "Class".  You access it's properties and methods using the "dot" notation: objWMI.Name.

A VBScript Class looks like the following:

 

1 Class CMyClass 2 3 Sub Class_Initialize 4 End Sub 5 6 Sub Class_Terminate 7 End Sub 8 9 End Class

The "Subs" re called on the creation of an instance and when an instance is destroyed.

Set objMyClass = new CMyclass

The class methods are called like any other object.  If CMyClass had a "Write" method we would call it like this: objMyClass.Write "Hello World!"

Why is this any different or better than using a plain old "Sub".  Bear with me a bit and I will show you some neat stuff and then maybe, some magic.

 

   1:  Class CLogFile
   2:   
   3:      Dim fso 'FSO object
   4:      Dim ofile ' FIle object
   5:      Dim sFileName ' saves the pre built filename
   6:      Dim bLocal ' ' Setinstance to use WScript.Echo instaed of file
   7:      
   8:      Sub Class_Initialize() ' this happens for every instance
   9:      
  10:          sFileName = sLogPath & "\" _        
  11:              & Right("0" & Month(Date),2) & "-" _        
  12:              & Right("0" & Day(Date),2) & "-"  _        
  13:              & Right(Year(Date),2) & "-"  _        
  14:              & DatePart("h", Now) & DatePart("n", Now) & ".txt"
  15:              Set fso = CreateObject("Scripting.FileSystemObject")        
  16:              
  17:      End Sub
  18:      
  19:      Sub Open( sLogPath ) 'Call at begiing of script     
  20:         
  21:          if sLogPath = "" Then             
  22:              bLocal = True      ' Echo don't use file       
  23:          Else  'open/create file     
  24:              Set ofile = fso.OpenTextFile(sFileName , 8,True)        
  25:              Write "Log file being opened"             
  26:          End If
  27:                  
  28:      
  29:      End Sub
  30:      
  31:      Sub Write( sMessage )  
  32:             
  33:          If Not bLocal Then              
  34:              ofile.WriteLine "[" & Now & "] " & sMessage          
  35:          Else              
  36:              WScript.Echo "[" & Now & "] " & sMessage          
  37:          End If    
  38:          
  39:      End Sub        
  40:      
  41:      Sub Close  ' call at end of script to timestamp the log closing.
  42:          Write "Log file being closed"
  43:          ofile.Close
  44:          ' clean up for good practice
  45:          Set ofile = Nothing
  46:      End Sub  
  47:       
  48:  End Class
  49:   

This is the bombshell I dropped on my friend.  It looks foreboding but in a bit you will see what it buys us.

1.  Encapsulation:

All variables required for the functionality of the included code are embedded in the class.  This makes it convenient to copy and paste as it doesn't need external feeding.  No more global FileSystemObject.  It's hidden inside the class

2.  Abstraction:

The functionality is totally hidden.  It just does what we want without having to think about how it's done.

3.  Portability

4.  Reusable Code:

Code can be used over and over to perform the same function without the need for redesign.

In the case of this LogFIle class the output format can be changed easily without changing any of the calling code.  This code uses a specific format for the file name which it generates.  This can be easily altered.  A method can easily be added to handle switching between formats for different uses.  The log lines contain a time stamp which can be easily turned on or off.

The actually version of this that I use is somewhat more complex as the "Write" method takes an array of values and the "Open" method takes a formatter spec.  The class can switch between text, CSV, HTML and XML outputs.  This allows the same code to be used over and over even in the same script.  Each "Set obj = new Class" can open a different output file with a different format.  This object can even output to the command line.  The Class I use outputs to either the command line StdOut or the StdErr or both.  I have a "Write" "WriteEx" and a "WriteError" method that are used to control where the output goes and how it is both tagged and formatted.

 Study the above code and you will see how it accomplishes numerous effects with very few lines of code. 

 Later I might publish my more sophisticated Log class. 

Saturday, March 03, 2007

ActiPro Syntax Highlighter - (updated)

The ActiPro Syntax Highlighter with PowerShell script.  Highlighting is correct.  Module was added to ActiPro by ActiPro support in a very short time showing that the ActiPro Editor is very flexible.  This code was highlighted and copied to HTML using the ActiPro SyntaxEditor.  The new semantic definition was added by simply adding a "dynamic" language definition and then opening the script file.  I saved the file as HTML and pasted it into WLW to get a test of the HTML conversion.  I also added a DIV to force the containment of the lines.

AcriPro Website

ActiPro has done an excellent job on this product suite.

(Thank you Keith Hill for the use of your CmdLet code for use as a test case.  It was the largest and most complex script I could find when I went looking)

# ---------------------------------------------------------------------
# Author:    Keith Hill
# Desc:      CMDLET to pretty print XML.
# Usage:     This file contains a function-based CMDLET.  In order to use
#            it, you must dot source the file into your shell e.g.:
#            PoSH> . c:\bin\format-xml.ps1
# Date:      08/09/2006
# ---------------------------------------------------------------------
function Format-Xml {
    param([string[]]$Path)
        
    begin {
        function PrettyPrintXmlString([string]$xml) {
            $tr = new-object System.IO.StringReader($xml)
            $settings = new-object System.Xml.XmlReaderSettings
            $settings.CloseInput = $true
            $settings.IgnoreWhitespace = $true
            $reader = [System.Xml.XmlReader]::Create($tr, $settings)
            
            $sw = new-object System.IO.StringWriter
            $settings = new-object System.Xml.XmlWriterSettings
            $settings.CloseOutput = $true
            $settings.Indent = $true
            $writer = [System.Xml.XmlWriter]::Create($sw, $settings)
            
            while (!$reader.EOF) {
                $writer.WriteNode($reader, $false)
            }
            $writer.Flush()
            
            $result = $sw.ToString()
            $reader.Close()
            $writer.Close()
            $result
        }
        
        function PrettyPrintXmlFile($path) {
            $rpath = resolve-path $path
            $contents = gc $rpath
            $contents = [string]::join([environment]::newline, $contents)
            PrettyPrintXmlString $contents
        }
    
        function Usage() {
            ""
            "USAGE"
            "    Format-Xml -Path <pathToXmlFile>"
            ""
            "SYNOPSIS"
            "    Formats the XML into a nicely indented form (ie pretty printed)."
            "    Outputs one <string> object for each XML file."
            ""
            "PARAMETERS"
            "    -Path <string[]>"
            "        Specifies path to one or more XML files to format with indentation."
            "        Pipeline input is bound to this parameter."
            ""
            "EXAMPLES"
            "    Format-Xml -Path foo.xml"
            "    Format-Xml foo.xml"
            "    gci *.xml | Format-Xml"  
            "    [xml]`"<doc>...</doc>`" | Format-Xml"
            ""
        }
        if (($args[0] -eq "-?") -or ($args[0] -eq "-help")) {
          Usage
        }
    }
    
    process {
        if ($_) {
          if ($_ -is [xml]) {
            PrettyPrintXmlString $_.get_OuterXml()
          }
          elseif ($_ -is [IO.FileInfo]) {
            PrettyPrintXmlFile $_.FullName
          }
          elseif ($_ -is [string]) {
            if (test-path -type Leaf $_) {
                PrettyPrintXmlFile $_
            }
            else {
                PrettyPrintXmlString $_
            }
          }
          else {
            throw "Pipeline input type must be one of: [xml], [string] or [IO.FileInfo]"
          }
        }
    }
      
    end {
        if ($Path) {
          foreach ($aPath in $Path) {
            PrettyPrintXmlFile $aPath
          }
        }
    }
}

 

 

Tuesday, February 27, 2007

Leo Vildosola's Code Snippet Plugin - Test post

The following code is just stuff laying around and is used only to test the plugin.  DOn't assume any of it is working as much cam from my junk folder where I park snippets that I may be using for other projects.  My intentions are to just see how well code embeds in teh blog and how the highlighting behaves.  To that end I chose large and possibly broken code to see what would happen.  It appears that the formatter behaves well.   Thankyou again Leo Vildosola.

HTML

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>
  <head>
    <b:include data='blog' name='all-head-content'/>
    <title><data:blog.pageTitle/></title>
    <b:skin><![CDATA[/*
-----------------------------------------------
Blogger Template Style
Name:     Minima
Designer: Douglas Bowman
URL:      www.stopdesign.com
Date:     26 Feb 2004
Updated by: Blogger Team
----------------------------------------------- */

/* Variable definitions
   ====================
   <Variable name="bgcolor" description="Page Background Color"
             type="color" default="#fff" value="#ffffef">
   <Variable name="textcolor" description="Text Color"
             type="color" default="#333" value="#333333">
   <Variable name="linkcolor" description="Link Color"
             type="color" default="#58a" value="#5588aa">
   <Variable name="pagetitlecolor" description="Blog Title Color"
             type="color" default="#666" value="#666666">
   <Variable name="descriptioncolor" description="Blog Description Color"
             type="color" default="#999" value="#999999">
   <Variable name="titlecolor" description="Post Title Color"
             type="color" default="#c60" value="#cc6600">
   <Variable name="bordercolor" description="Border Color"
             type="color" default="#ccc" value="#cccccc">
   <Variable name="sidebarcolor" description="Sidebar Title Color"
             type="color" default="#999" value="#999999">
   <Variable name="sidebartextcolor" description="Sidebar Text Color"
             type="color" default="#666" value="#666666">
   <Variable name="visitedlinkcolor" description="Visited Link Color"
             type="color" default="#999" value="#999999">
   <Variable name="bodyfont" description="Text Font"
             type="font" default="normal normal 100% Georgia, Serif" value="normal normal 100% Georgia, Serif">
   <Variable name="headerfont" description="Sidebar Title Font"
             type="font"
             default="normal normal 78% 'Trebuchet MS',Trebuchet,Arial,Verdana,Sans-serif" value="normal normal 78% 'Trebuchet MS',Trebuchet,Arial,Verdana,Sans-serif">
   <Variable name="pagetitlefont" description="Blog Title Font"
             type="font"
             default="normal normal 200% Georgia, Serif" value="normal normal 200% Georgia, Serif">
   <Variable name="descriptionfont" description="Blog Description Font"
             type="font"
             default="normal normal 78% 'Trebuchet MS', Trebuchet, Arial, Verdana, Sans-serif" value="normal normal 78% 'Trebuchet MS', Trebuchet, Arial, Verdana, Sans-serif">
   <Variable name="postfooterfont" description="Post Footer Font"
             type="font"
             default="normal normal 78% 'Trebuchet MS', Trebuchet, Arial, Verdana, Sans-serif" value="normal normal 78% 'Trebuchet MS', Trebuchet, Arial, Verdana, Sans-serif">
*/

/* Use this with templates/template-twocol.html */

body {
  background:$bgcolor;
  margin:0;
  color:$textcolor;
  font:x-small Georgia Serif;
  font-size/* */:/**/small;
  font-size: /**/small;
  text-align: center;
  }
a:link {
  color:$linkcolor;
  text-decoration:none;
  }
a:visited {
  color:$visitedlinkcolor;
  text-decoration:none;
  }
a:hover {
  color:$titlecolor;
  text-decoration:underline;
}
a img {
  border-width:0;
  }

/* Header
-----------------------------------------------
 */

#header-wrapper {
  width:880px;
  margin:0 auto 10px;
  border:1px solid $bordercolor;
  }

#header { 
  margin: 5px;
  border: 1px solid $bordercolor;
  text-align: center;
  color:$pagetitlecolor;
}

#header h1 {
  margin:5px 5px 0;
  padding:15px 20px .25em;
  line-height:1.2em;
  text-transform:uppercase;
  letter-spacing:.2em;
  font: $pagetitlefont;
}

#header a {
  color:$pagetitlecolor;
  text-decoration:none;
  }

#header a:hover {
  color:$pagetitlecolor;
  }

#header .description {
  margin:0 5px 5px;
  padding:0 20px 15px;
  max-width:700px;
  text-transform:uppercase;
  letter-spacing:.2em;
  line-height: 1.4em;
  font: $descriptionfont;
  color: $descriptioncolor;
 }


/* Outer-Wrapper
----------------------------------------------- */
#outer-wrapper {
  width: 880px;
  margin:0 auto;
  padding:10px;
  text-align:left;
  font: $bodyfont;
  }

#main-wrapper {
  width: 600px;
  float: left;
 /* word-wrap: break-word;*/ /* fix for long text breaking sidebar float in IE */
 overflow: hidden;   /* fix for long non-text content breaking IE sidebar float */
  }

#sidebar-wrapper {
  width: 220px;
  float: right;
  word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
  overflow: hidden;      /* fix for long non-text content breaking IE sidebar float */
}


/* Headings
----------------------------------------------- */

h2 {
  margin:1.5em 0 .75em;
  font:$headerfont;
  line-height: 1.4em;
  text-transform:uppercase;
  letter-spacing:.2em;
  color:$sidebarcolor;
}


/* Posts
-----------------------------------------------
 */
h2.date-header {
  margin:1.5em 0 .5em;
  }

.post {
  margin:.5em 0 1.5em;
  border-bottom:1px dotted $bordercolor;
  padding-bottom:1.5em;
  }
.post h3 {
  margin:.25em 0 0;
  padding:0 0 4px;
  font-size:140%;
  font-weight:normal;
  line-height:1.4em;
  color:$titlecolor;
}

.post h3 a, .post h3 a:visited, .post h3 strong {
  display:block;
  text-decoration:none;
  color:$titlecolor;
  font-weight:normal;
}

.post h3 strong, .post h3 a:hover {
  color:$textcolor;
}

.post p {
  margin:0 0 .75em;
  line-height:1.6em;
}

.post-footer {
  margin: .75em 0;
  color:$sidebarcolor;
  text-transform:uppercase;
  letter-spacing:.1em;
  font: $postfooterfont;
  line-height: 1.4em;
}

.comment-link {
  margin-left:.6em;
  }
.post img {
  padding:4px;
  border:1px solid $bordercolor;
  }
.post blockquote {
  margin:1em 20px;
  }
.post blockquote p {
  margin:.75em 0;
  }

/* Comments
----------------------------------------------- */
#comments h4 {
  margin:1em 0;
  font-weight: bold;
  line-height: 1.4em;
  text-transform:uppercase;
  letter-spacing:.2em;
  color: $sidebarcolor;
  }

#comments-block {
  margin:1em 0 1.5em;
  line-height:1.6em;
  }
#comments-block .comment-author {
  margin:.5em 0;
  }
#comments-block .comment-body {
  margin:.25em 0 0;
  }
#comments-block .comment-footer {
  margin:-.25em 0 2em;
  line-height: 1.4em;
  text-transform:uppercase;
  letter-spacing:.1em;
  }
#comments-block .comment-body p {
  margin:0 0 .75em;
  }
.deleted-comment {
  font-style:italic;
  color:gray;
  }

#blog-pager-newer-link {
  float: left;
 }
 
#blog-pager-older-link {
  float: right;
 }

#blog-pager { 
  text-align: center;
 }

.feed-links {
  clear: both;
  line-height: 2.5em;
}

/* Sidebar Content
----------------------------------------------- */
.sidebar { 
  color: $sidebartextcolor;
  line-height: 1.5em;
 }

.sidebar ul {
  list-style:none;
  margin:0 0 0;
  padding:0 0 0;
}
.sidebar li {
  margin:0;
  padding:0 0 .25em 15px;
  text-indent:-15px;
  line-height:1.5em;
  }

.sidebar .widget, .main .widget { 
  border-bottom:1px dotted $bordercolor;
  margin:0 0 1.5em;
  padding:0 0 1.5em;
 }

.main .Blog { 
  border-bottom-width: 0;
}


/* Profile 
----------------------------------------------- */
.profile-img { 
  float: left;
  margin: 0 5px 5px 0;
  padding: 4px;
  border: 1px solid $bordercolor;
}

.profile-data {
  margin:0;
  text-transform:uppercase;
  letter-spacing:.1em;
  font: $postfooterfont;
  color: $sidebarcolor;
  font-weight: bold;
  line-height: 1.6em;
}

.profile-datablock { 
  margin:.5em 0 .5em;
}

.profile-textblock { 
  margin: 0.5em 0;
  line-height: 1.6em;
}

.profile-link { 
  font: $postfooterfont;
  text-transform: uppercase;
  letter-spacing: .1em;
}

/* Footer
----------------------------------------------- */
#footer {
  width:660px;
  clear:both;
  margin:0 auto;
  padding-top:15px;
  line-height: 1.6em;
  text-transform:uppercase;
  letter-spacing:.1em;
  text-align: center;
}

/** Page structure tweaks for layout editor wireframe */
body#layout #header { 
  margin-left: 0px;
  margin-right: 0px;
}
]]></b:skin>
  </head>

  <body>
  <div id='outer-wrapper'><div id='wrap2'>

    <!-- skip links for text browsers -->
    <span id='skiplinks' style='display:none;'>
      <a href='#main'>skip to main </a> |
      <a href='#sidebar'>skip to sidebar</a>
    </span>

    <div id='header-wrapper'>
      <b:section class='header' id='header' maxwidgets='1' showaddelement='no'>
<b:widget id='Header1' locked='true' title='tech-comments (Header)' type='Header'/>
</b:section>
    </div>
 
    <div id='content-wrapper'>

      <div id='main-wrapper'>
        <b:section class='main' id='main' showaddelement='no'>
<b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog'/>
</b:section>
      </div>

      <div id='sidebar-wrapper'>
        <b:section class='sidebar' id='sidebar' preferred='yes'>
<b:widget id='LinkList2' locked='false' title='Feeds' type='LinkList'/>
<b:widget id='Profile1' locked='false' title='About Me' type='Profile'/>
<b:widget id='LinkList1' locked='false' title='Links' type='LinkList'/>
<b:widget id='BlogArchive1' locked='false' title='Blog Archive' type='BlogArchive'/>
</b:section>
      </div>

      <!-- spacer for skins that want sidebar and main to be the same height-->
      <div class='clear'>&#160;</div>

    </div> <!-- end content-wrapper -->

    <div id='footer-wrapper'>
      <b:section class='footer' id='footer'/>
    </div>

  </div></div> <!-- end outer-wrapper -->
</body>
</html>
                

 

PowerShell

$x|foreach {Get-Acl

 $_.Fullname $_|add-member -membertype noteproperty -name Owner3 -value $owner }



function Add-Owner( $obj){
     $owner=(Get-Acl $obj.Fullname).Owner
     $obj|add-member -membertype noteproperty -name Owner -value $owner
}

$files=dir c:\ -filter *.zip -recurse
$files | foreach {add-owner( $_) }
$files | select-object -property fullname,extension,length,LastWriteTime,owner|export-csv d:\files.txt -notype



# AdOwnerToFile.ps1
#  Cut and paste to PS.  Change the "DIR" filter and path as needed.
# function is separated out for re-use
function Add-Owner( $obj){
     $owner=(Get-Acl $obj.Fullname).Owner
     $obj|add-member -membertype noteproperty -name Owner -value $owner
}
 
# get a filtered list of files
$files=dir c:\ -filter *.zip -recurse
 
# add the owner as a "note" property on each file
$files | foreach {add-owner( $_) }
 
# use select-object to select fields and field order to send to Export-Csv
$files | select-object -property  fullname,extension,length,LastWriteTime,owner|export-csv d:\files.txt -notype

C#.Net

using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.Management.Automation;
using System.Collections;

namespace DSS.PowerShell
{
    [Cmdlet(VerbsDiagnostic.Ping, "Computer", SupportsShouldProcess = true)]
    public class PingComputerCmd : PSCmdlet
    {

        #region Properties

        private string[] _Name = {"localhost"};
        private Boolean _All = false;
        private int _Output = 0;
        
        [Parameter(Position = 0,
          Mandatory = false,
          ValueFromPipelineByPropertyName = true,
          HelpMessage = "Help Text")]
        [ValidateNotNullOrEmpty]
        
        public string[] Name
        {
            get
            { 
               return _Name;
            }        
            
            set{
                _Name = value;        
            }
        }

        [Parameter(Position = 1, Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Return all objects")]
            public bool All
            {
                get
                {
                    return false;
                }
                set
                {
                    _All = value;
                }
            }

        [Parameter(Position = 2, Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Return all objects")]
        public int Output
        {
            get
            {
                return 0;
            }
            set
            {
                _Output = value;
            }
        }
        #endregion
            
        protected override void ProcessRecord()
        {
                if (_Name.Length == 1)  // see if it's a filename
                {
                    if (System.IO.File.Exists(_Name[0]))
                    {
                        _Name = System.IO.File.ReadAllLines(_Name[0]);
                    }
                }
                foreach (string ThisName in _Name)
                {
                    WriteDebug("Attempting to ping " + ThisName);
                    SelectQuery Query = new SelectQuery("SELECT StatusCode FROM Win32_PingStatus WHERE Address = '" + ThisName + "'");
                    ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Query);
                   foreach (ManagementObject result in Searcher.Get())
                    {
                        try
                        {
                            string statusCode = result.GetPropertyValue("StatusCode").ToString();
                            if (statusCode == "0")
                            {
                                WriteDebug("Successful ping of " + ThisName);
                                if ( _Output == 0 ) WriteObject("Good:" + ThisName);
                                else WriteObject(ThisName);
                            }
                        }
                        catch (Exception)
                        {
                            if (_All)
                            {
                                WriteObject("Exc:" + ThisName );
                            }
                       }
                    }
                }
            }
            }
        }