<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>vishinde</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/vishinde/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/vishinde/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:54:08 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Interacting with System Registry using WMI</title>
      <link>https://docs.microsoft.com/archive/blogs/vishinde/interacting-with-system-registry-using-wmi</link>
      <pubDate>Sat, 15 Sep 2012 22:23:00 GMT</pubDate>
      <dc:creator><![CDATA[Vivek Shinde]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/vishinde/2012/09/15/interacting-with-system-registry-using-wmi/</guid>
      <description><![CDATA[The utility of WMI classes is huge and there are a lot of WMI classes to interact with. Which is of...]]></description>
      <content:encoded><![CDATA[<p>The utility of WMI classes is huge and there are a lot of WMI classes to interact with. Which is of course an awesome thing, but since there are lot of WMI&nbsp;classes sometimes the challenge is figuring out which class you will need for your specific requirement.</p>
<p>Today, lets discuss a WMI class which you will need for interacting with the registry - and the class is <strong>StdRegProv.</strong></p>
<p>A little bit of details on the StdRegProv class before we start:</p>
<p>StdRegProv has been a part of Root\Default WMI namespace. However, starting from Windows Vista it is also a part of Root\CIMV2 namespace. Therefore, one can create an instance of StdRegProv class from Root\CIMV2 or Root\Default Namespace. Consider using the Root\Default namespace, if you want your script to be compatible with older versions of Windows Operating System as well.</p>
<p>There is one more thing I want to focus your attention to&nbsp;about this class. You will need following specific numeric values to interact with specific registry hives. Below are the hives and their corresponding numeric values:</p>
<p>&nbsp;<strong>Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Value</strong></p>
<p>HKEY_CLASSES_ROOT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2147483648</p>
<p>HKEY_CURRENT_USER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2147483649</p>
<p>HKEY_LOCAL_MACHINE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2147483650</p>
<p>HKEY_USERS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2147483651</p>
<p>HKEY_CURRENT_CONFIG&nbsp;&nbsp;&nbsp;&nbsp; 2147483653</p>
<p>Not to digress, but while&nbsp;writing these values I just realized that this one makes for an excellent example&nbsp;of use of&nbsp;HashTable, doesn't it! Just create a HashTable with the keys as the hive names and assign the corresponding number as the value&nbsp;of each key. Below is an example of what I am talking about:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1385.hashtable.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1385.hashtable.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1385.hashtable.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1385.hashtable.png" border="0" /></a></p>
<p></p>
<p>Now, it indeed becomes easy to access the numeric value of any hive (e.g. $regkey["HKEY_CLASSES_ROOT"] )</p>
<p>Having understood the important pieces of the StdRegProv class, now lets proceed with looking at some useful methods of this class. For this post, I am using the class from Root\Default namespace. Following are the two ways in which we can create a reference to this WMI class:</p>
<p>1. <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/5543.WMIClassStdRegProv.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/5543.WMIClassStdRegProv.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/5543.WMIClassStdRegProv.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/5543.WMIClassStdRegProv.png" border="0" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1411.WMIClassStdRegProv.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1411.WMIClassStdRegProv.png"></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1033.WMIClassStdRegProv.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1033.WMIClassStdRegProv.png"></a></p>
<p>&nbsp;</p>
<p>2. <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/5280.GetWmiStdRegProv.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/5280.GetWmiStdRegProv.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/5280.GetWmiStdRegProv.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/5280.GetWmiStdRegProv.png" border="0" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4760.WMIClassStdRegProv.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4760.WMIClassStdRegProv.png"></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/0250.GetWmiStdRegProv.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/0250.GetWmiStdRegProv.png"></a></p>
<p>If you have any doubts on the above&nbsp;2 methods of referencing a WMI class please refer to my "Introduction to WMI" (<a href="https://blogs.msdn.com/b/vishinde/archive/2012/09/15/introduction-to-wmi.aspx">https://blogs.msdn.com/b/vishinde/archive/2012/09/15/introduction-to-wmi.aspx</a>)&nbsp;blog post.</p>
<p>The advantage of using Get-WMIObject over [WMIClass] type accelerator is that Get-WMIObject has a -ComputerName parameter. That means you can fetch registry information from a remote machine very easily using the Get-WMIObject cmdlet. That is:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/0511.RemoteComputer.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/0511.RemoteComputer.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/0511.RemoteComputer.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/0511.RemoteComputer.png" border="0" /></a></p>
<p>Using&nbsp;a Get-Member on the $regClass will list all the static members of the class:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4035.RegMethods.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4035.RegMethods.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4035.RegMethods.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4035.RegMethods.png" border="0" /></a></p>
<p>Formatting this output in a tabular format and wrapping the contents will list all the parameters which are expected by this method as well ( $regClass | Get-Member | Format-Table -Wrap ).</p>
<p>We can use any of the Get.. methods in order to get a value from the registry. Lets say we want to retrieve a String value from the registry, in that case we will use the GetStringValue method. In the example below, we are reading the value of ExecutionPolicy key in the Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell folder. As a reminder, $regkey &nbsp;is a HashTable we created earlier and HKEY_LOCAL_MACHINE is one of the keys of the HashTable.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/6740.GetStringValue.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/6740.GetStringValue.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/6740.GetStringValue.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/6740.GetStringValue.png" border="0" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/7142.GetStringValue.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/7142.GetStringValue.png"></a></p>
<p>In the output, ReturnValue 0 tells us that the operation was successful and sValue is the actual value. If you want to read just the ouptut, you can Select sValue from the output as shown in the example above.</p>
<p>Just like you can read different types of values using this class, you can read the keys and the values as well using this class. Example:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1537.EnumKey.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1537.EnumKey.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1537.EnumKey.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1537.EnumKey.png" border="0" /></a></p>
<p>sNames is an array returned by EnumKey, hence we chose to use the ExpandProperty parameter on sNames to display all the Keys on a particular path. (Not sure what ExpandProperty parameter does? Check out my blog post on ExpandProperty parameter).</p>
<p>Just like you have EnumKey, there is also an EnumValue method, which lists the Valuenames in a particular key.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4848.EnumValues.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4848.EnumValues.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4848.EnumValues.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4848.EnumValues.png" border="0" /></a></p>
<p>I think this post would remain incomplete if I didn't mention Invoke-WMIMethod cmdlet. Since we are calling static methods on the&nbsp;WMI class, we can also use Invoke-WMIMethod to call all the methods we have discussed in this post. I want to give you one example of using the Invoke-WMIMethod (to call EnumValues method). Just like we could call EnumValues, we can call any of the methods we have discussed in this blogpost.</p>
<p>According to me, one of the most important advantage offered by these cmdlets (Get-WMIObject and Invoke-WMIMethod)&nbsp;is that you have a -ComputerName and a -Credential parameter. That means you can connect to a remote machine using different credentials when you are using these WMI cmdlets.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/8688.InvokeWMIRegistry.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/8688.InvokeWMIRegistry.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/8688.InvokeWMIRegistry.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/8688.InvokeWMIRegistry.png" border="0" /></a></p>
<p>Hopefully, this post gave you a good enough idea of how to interact with the registry on local or remote machine using WMI. Using this class you can create as well as delete keys or values. Doing a Get-Member along with a Format-Table -Wrap on the output will give you a good enough understanding of leveraging the different methods further. Just keep in mind that whenever you see hDefKey (Int32) parameter for any of these methods, you are supposed to pass the numeric value of a registry hive to that method.</p>
<p>This approach should be useful if you want to interact with registry on remote machines and don't have PowerShell v2 Remoting enabled on your remote machine yet. If you have PowerShell v2 Remoting enabled, its just about using *-Item and *-ItemProperty related cmdlets to interact with the Registry instead of doing this!</p>]]></content:encoded>
    </item>
    <item>
      <title>Introduction to WMI</title>
      <link>https://docs.microsoft.com/archive/blogs/vishinde/introduction-to-wmi</link>
      <pubDate>Sat, 15 Sep 2012 11:44:05 GMT</pubDate>
      <dc:creator><![CDATA[Vivek Shinde]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/vishinde/2012/09/15/introduction-to-wmi/</guid>
      <description><![CDATA[I have been thinking of writing a few blog posts on&nbsp;leveraging some useful&nbsp;WMI classes...]]></description>
      <content:encoded><![CDATA[<p>I have been thinking of writing a few blog posts on&nbsp;leveraging some useful&nbsp;WMI classes through PowerShell. Before moving into those examples, I&nbsp;thought&nbsp;it would be better to create a blog post on essential cmdlets in WMI so that I can ask you to refer to this post while discussing examples.</p>
<p>In this blog post, we will focus on Get-WMIObject, Invoke-WMIMethod and [WMIClass] type accelerator.</p>
<p>Lets start with Get-WMIObject first. Get-WMIObject is used to create instances of WMI classes. Using this cmdlet, we can create objects of WMI classes and start using members (methods and properties) of the WMI&nbsp;objects.</p>
<p>Example, lets create an instance of win32_process class. Once you do a Get-Member on that object, you will get a list of instance members you can access on that object. Also, if you refer to the example below, you will see that the Type of the object &nbsp;is System.Management.Management<strong>Object</strong>. In other words, we created an "object" of win32_process WMI class. All the members are instance members and we can access them using the win32_process object e.g. $procObj.ProcessName.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/6332.GetWmiObject.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/6332.GetWmiObject.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/6332.GetWmiObject.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/6332.GetWmiObject.png" border="0" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/8662.GetWmiObject.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/8662.GetWmiObject.png"></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/3603.GetWmiObject.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/3603.GetWmiObject.png"></a></p>
<p>&nbsp;</p>
<p>Now lets look at [WMIClass]. [WMIClass] is a type accelerator for creating ManagementClass. What's the need of referring to a class? In WMI, there are instance members and static members. Static members are accessed on the class itself. So, if you want to access any static members of a WMI class you could use the WMIClass type accelerator. In the example below, you can see that [WMIClass] creates a System.Management.Management<strong>Class</strong> type. Apart from that, also notice that this time the members which you see are static members of the win32_process class.&nbsp;Now we&nbsp;can call the Create static method by using $processClass.Create, because $processClass is a <strong>class</strong> and static members can be referred to on a class. That is, we can say:</p>
<p>$processClass.Create("notepad.exe").</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4137.WMIClass.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4137.WMIClass.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4137.WMIClass.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4137.WMIClass.png" border="0" /></a></p>
<p>&nbsp;</p>
<p>Now lets look at a different way of referencing a WMI class - using Get-WMIObject cmdlet. Along with creating instance of a WMI class, the Get-WMIObject cmdlet can also used for listing the WMI classes using the -list parameter. Once we have that list, we can filter any of the specific classes we want through this list. That selected class would be our reference of a WMI class. Lets look at an example of that:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/2783.ListWMIClass.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/2783.ListWMIClass.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/2783.ListWMIClass.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/2783.ListWMIClass.png" border="0" /></a></p>
<p>So you will notice that the class type is same as the type name&nbsp;generated by the&nbsp;[WMIClass] type accelerator. There is a huge&nbsp;advantage in using this method over [WMIClass] and we will look into this when we discuss different examples of WMI (Hint: Think Remoting to different machines).</p>
<p>Now we can use the Static method "Create" of the Win32_Process class using the class reference $procClass:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1323.CreateProcess.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1323.CreateProcess.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1323.CreateProcess.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1323.CreateProcess.png" border="0" /></a></p>
<p>&nbsp;</p>
<p>That's one way of calling static members of a WMI class. However, PowerShell also gives you a cmdlet of calling methods of WMI classes, and the cmdlet is Invoke-WMIMethod. Following example shows use of Invoke-WMIMethod:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1055.InvokeWMI.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1055.InvokeWMI.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1055.InvokeWMI.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1055.InvokeWMI.png" border="0" /></a></p>
<p>We provide the WMI class name to -Class parameter, method name to -Name parameter and parameters for the method to the -ArgumentList parameter. It also has a parameter which may be of amazing interest to you <strong>-ComputerName.&nbsp;</strong>Using this cmdlet,&nbsp;you can run methods on remote machines as well.</p>
<p>Hopefully, this article gave you a good overview of different ways of interacting with WMI classes. There are other WMI type accelerators as well, such as [WMISearcher], but we&nbsp;should be good to start interacting with WMI with an&nbsp;understanding&nbsp;of what we discussed in this blog.&nbsp;Again, I will refer you to this post, when needed, while discussing about different&nbsp;WMI classes.</p>]]></content:encoded>
    </item>
    <item>
      <title>ExpandProperty in Select-Object</title>
      <link>https://docs.microsoft.com/archive/blogs/vishinde/expandproperty-in-select-object</link>
      <pubDate>Mon, 27 Aug 2012 09:03:17 GMT</pubDate>
      <dc:creator><![CDATA[Vivek Shinde]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/vishinde/2012/08/27/expandproperty-in-select-object/</guid>
      <description><![CDATA[While discussing about the Select-Object cmdlet, I love to mention about the ExpandProperty...]]></description>
      <content:encoded><![CDATA[<p>While discussing about the Select-Object cmdlet, I love to mention about the ExpandProperty parameter since it is cool and of great utility.&nbsp;Sometimes&nbsp;the utility of the ExpandProperty parameter is better understood by looking at examples. So here are some examples which will help you understand the ExpandProperty parameter of the Select-Object cmdlet:</p>
<p>Before diving into examples, lets go through the Get-Help information of ExpandProperty parameter of Select-Object cmdlet. It states - <em>Specifies a property to select, and indicates that an attempt should be made to expand that property.</em></p>
<p>In other words - ExpandProperty expands the collections. That is, it will output the properties of every object in the collection.</p>
<p>Following examples will make ExpandProperty more clear. Let's start with Get-Process cmdlet.</p>
<p>Get-Process | Get-Member gives us&nbsp;different properties of "process" object. Let's focus on &nbsp;the Modules property which is a ProcessModule<strong>Collection:</strong></p>
<p><strong></strong>&nbsp;</p>
<p><strong><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/2352.Process_Modules.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/2352.Process_5F00_Modules.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/2352.Process_Modules.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/2352.Process_5F00_Modules.png" border="0" /></a></strong></p>
<p><strong></strong>&nbsp;</p>
<p>Now, lets select the property Modules:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/0552.SelectModules.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/0552.SelectModules.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/0552.SelectModules.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/0552.SelectModules.png" border="0" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/5670.SelectModules.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/5670.SelectModules.png"></a></p>
<p>You will see that the output does not seem to be complete. That's because Modules is a collection and it has a collection of objects inside it. In order to display each object and its properties, you will have to use the ExpandProperty parameter of Select-Object. Let's look at the output generated using -ExpandProperty parameter before we discuss more about it:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4848.ExpandModules.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4848.ExpandModules.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4848.ExpandModules.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4848.ExpandModules.png" border="0" /></a></p>
<p><strong></strong></p>
<p>Now you can see that since we used the ExpandProperty parameter, Select-Object "expanded" on the collection and displayed properties (Size, ModuleName and FileName)&nbsp;of each object inside the collection.</p>
<p>(Just a note: In the above example, I used Get-Process <strong>notepad</strong> just to reduce the output on my screen (by getting only notepad process related information) to give you a better view of what was happening. If you are using the same example, be sure to start a notepad process on your machine. Get-Process | Select-Object -ExpandProperty Modules would also give us a similar result, just that in that case it would be a lot of data outputted).</p>
<p>Let's look at another example here. Lets look at DependentServices property of "service" object. Let's start with Get-Service | Get-Member:</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/7127.Service_Dependent.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/7127.Service_5F00_Dependent.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/7127.Service_Dependent.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/7127.Service_5F00_Dependent.png" border="0" /></a></p>
<p>You see that DependentServices is an array of "service" (ServiceController) object. In other words, it can be looked at as a collection of service objects. That's the reason if we try to just Select-Object -Property DependentServices on Get-Service, we wont be able to get a complete view of the DependentServices.</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/0572.Service_Dependent_Property.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/0572.Service_5F00_Dependent_5F00_Property.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/0572.Service_Dependent_Property.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/0572.Service_5F00_Dependent_5F00_Property.png" border="0" /></a></p>
<p>&nbsp;</p>
<p>Now. let's use the ExpandProperty on DependentServices and see the difference..</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/5773.Service_Dependent_ExpandedProperty.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/5773.Service_5F00_Dependent_5F00_ExpandedProperty.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/5773.Service_Dependent_ExpandedProperty.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/5773.Service_5F00_Dependent_5F00_ExpandedProperty.png" border="0" /></a></p>
<p>&nbsp;</p>
<p>Because we used ExpandProperty we are able to see the expanded collection.</p>
<p>(Another note: In this case, rather than getting all the services, I just got the&nbsp;"samss" service (Get-Service samss), that's just to give you a better view of how the ExpandProperty parameter works. The service name is not important in this example, however what is important is that you need to get service which has some dependent services. In case you don't have the same service or if&nbsp;you want to check the property for some other service, here is a statement to fetch the services which have some dependent services:</p>
<p>Get-Service | Where-Object { $_.DependentServices }</p>
<p>To get an even better view you can fetch services which have more than 1 dependent services. For that,&nbsp;you can use the following statement:</p>
<p>Get-Service | Where-Object { ($_.DependentServices).count -gt 1 } )</p>
<p>Hopefully, these examples&nbsp;gave you a good understanding of ExpandProperty parameter of Select-Object cmdlet.</p>
<p>There is one another&nbsp;interesting and useful aspect to the ExpandProperty parameter. Till now, we applied ExpandProperty to the properties which were "collection" of some kind. If you apply ExpandProperty to a property which is not a collection, it gives you just the values not the object with properties. This example below should make it more clear:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1513.Service_Name_ExpandProperty.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1513.Service_5F00_Name_5F00_ExpandProperty.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/1513.Service_Name_ExpandProperty.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/1513.Service_5F00_Name_5F00_ExpandProperty.png" border="0" /></a></p>
<p>&nbsp;</p>
<p>If you pipe this is to Get-Member cmdlet, you will be able to see that the output is of&nbsp;"string" type and&nbsp;not anymore a "selected" object with "name" as a property of that object. And if you pipe this output to Get-Member you will see that the output is of type string.</p>
<p>You can use this output in multiple ways,depending on your requirements. One example would be&nbsp;- check if any service related cmdlets (Start-Service, Stop-Service) have parameter which "Accepts Pipeline Input" <em><strong>by value</strong></em> in "string" type. Now you can pipe this string output into&nbsp;your specific *service cmdlet and generate the required result. Once you go through my "Pipeline in PowerShell" blog, I am sure you will get why Accept Pipeline by value will work..</p>
<p>&nbsp;</p>
<p>Another example of ExpandProperty on similar lines: This time lets expand the Id&nbsp;property of Get-Process cmdlet. Before that, let's do a Get-Member on Get-Process and take a look at the Id property:</p>
<p>Get-Process | Get-Member:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/2117.Process_Member.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/2117.Process_5F00_Member.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/2117.Process_Member.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/2117.Process_5F00_Member.png" border="0" /></a></p>
<p>&nbsp;</p>
<p>So we know that Id is a property of "process" object and it is of type integer. Now, lets expand the property and check the output:</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4370.Process_Expand_Id.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4370.Process_5F00_Expand_5F00_Id.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/4370.Process_Expand_Id.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/4370.Process_5F00_Expand_5F00_Id.png" border="0" /></a></p>
<p>This time as well, you see that we get the Id of processes as values not as properties of "selected" object. Pipe this output to Get-Member and you will see that the values are of type int.</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/3125.Process_Expand_Id_Type.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/3125.Process_5F00_Expand_5F00_Id_5F00_Type.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/3125.Process_Expand_Id_Type.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/3125.Process_5F00_Expand_5F00_Id_5F00_Type.png" border="0" /></a></p>
<p>Now you can see that when ExpandProperty is applied on properties which are not collections, we get the values (not "selected" objects with properties) and the values retain the original datatype of the properties.&nbsp;</p>
<p>Hopefully, these examples helped you to&nbsp;understand in detail the ExpandProperty parameter of Select-Object cmdlet.</p>]]></content:encoded>
    </item>
    <item>
      <title>Pipeline in PowerShell</title>
      <link>https://docs.microsoft.com/archive/blogs/vishinde/pipeline-in-powershell</link>
      <pubDate>Mon, 20 Aug 2012 20:10:00 GMT</pubDate>
      <dc:creator><![CDATA[Vivek Shinde]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/vishinde/2012/08/20/pipeline-in-powershell/</guid>
      <description><![CDATA[As a PFE, I travel quite a bit to different customer locations. Today, while sitting at the...]]></description>
      <content:encoded><![CDATA[<p></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">As a PFE, I travel quite a bit to different customer locations. Today, while sitting </span>at the airport waiting to board my flight, I started wondering about the pipeline in PowerShell. If you think of it, the airplane could be correlated to a pipeline from which we humans and other objects (such as bags etc.) are passed from one place to another. <span style="color: black; mso-bidi-font-family: Arial;">Yeah, too much of PowerShell could do that to you.. you start seeing objects and pipeline everywhere! :)</span><span style="color: black;"><o:p></o:p></span></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">On that thought, I decided to blog about pipeline in PowerShell while waiting to be "piped" from my current location to my destination!</span><span style="color: black;"><o:p></o:p></span></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">There are a few aspects of pipeline which I'd like to discuss in this blog post. Firstly, <strong><span style="text-decoration: underline;"><span style="mso-bidi-font-family: Arial;">what</span></span></strong> is passed through the pipeline and <strong><span style="text-decoration: underline;"><span style="mso-bidi-font-family: Arial;">when </span></span></strong>can you use pipeline.&nbsp;</span><span style="color: black; mso-bidi-font-family: Arial;">To begin with, let's look into what passes through the pipeline...</span></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">Since this blog's scope is pipeline and not cmdlets, I am not going into detail of following cmdlets which I am using for demonstration - </span></span><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">Get-Process, Foreach-Object, Start-Sleep&nbsp;and Import-CSV.</span></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">Let's start with one of the well-known cmdlets - Get-Process. Get-Process returns "process" objects, we can verify that by using Get-Process | Get-Member. The result will tell you that the cmdlet&nbsp;outputs<br />"Process" objects:</span><span style="color: black;"><o:p></o:p></span></span></p>
<p></p>
<p><span style="font-family: verdana,geneva; font-size: small;"></span>&nbsp;</p>
<p><span style="font-family: verdana,geneva; font-size: small;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/3755.ProcessObject.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/3755.ProcessObject.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/3755.ProcessObject.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/3755.ProcessObject.png" border="0" /></a></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">Now lets pipe this output into the foreach-object cmdlet:</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">Get-Process | Foreach-Object { $_ }</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">The output seems the same if compared&nbsp;with the output from Get-Process cmdlet:</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/8156.getprocess.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/8156.getprocess.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/8156.getprocess.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/8156.getprocess.png" border="0" /></a></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">Let's do some changes to the statement above to get a better </span><span style="font-family: verdana,geneva; font-size: small;">understanding of what exactly is happening. Let&rsquo;s add a delay of 1 second to </span><span style="font-family: verdana,geneva; font-size: small;">the output by using Start-Sleep -seconds 1 cmdlet:</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">Get-Process | Foreach-Object { Start-Sleep -seconds 1; $_ }</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">This might give you a better view of the fact that&nbsp;objects </span><span style="font-family: verdana,geneva; font-size: small;">are being passed through the pipeline and worked on asynchronously by the </span><span style="font-family: verdana,geneva; font-size: small;">foreach-object cmdlet. However, you saw only ProcessName, WS,&nbsp;VM etc. in</span><br /><span style="font-family: verdana,geneva; font-size: small;">the header of the output. Does that mean only these pieces of objects were </span><span style="font-family: verdana,geneva; font-size: small;">passed through the pipeline? Certainly not, PowerShell is just displaying the </span><span style="font-family: verdana,geneva; font-size: small;">specific properties of the "process" objects. We can confirm that by </span><span style="font-family: verdana,geneva; font-size: small;">using Get-Member on our sequence of cmdlets:</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">Get-Process&nbsp;| Foreach-Object { $_ } | Get-Member</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">The above statement will display all the properties of the process </span><span style="font-family: verdana,geneva; font-size: small;">object.&nbsp;If you compare, the&nbsp;output is similar to Get-Process | </span><span style="font-family: verdana,geneva; font-size: small;">Get-Member. This demonstrates that entire process object is passed from the source</span><br /><span style="font-family: verdana,geneva; font-size: small;">to destination cmdlet.</span></p>
<p>&nbsp;<span style="font-family: verdana,geneva; font-size: small;">Now that we understand objects are passed through the pipeline, </span><span style="font-family: verdana,geneva; font-size: small;">let&rsquo;s move on to the next objective of this blog &ndash; &lsquo;<i>when can you use the pipeline&rsquo;</i>.</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">Let&rsquo;s take an example of Start-Service cmdlet and&nbsp;focus our </span><span style="font-family: verdana,geneva; font-size: small;">attention on the "Name" parameter of the Start-Service cmdlet.</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">Let's do Get-Help Start-Service -Parameter Name to get only </span><span style="font-family: verdana,geneva; font-size: small;">"Name" related help information.</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/6165.parametername.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/6165.parametername.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/6165.parametername.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/6165.parametername.png" border="0" /></a></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">Accept Pipeline Input - true - tells us that information can be piped into this parameter. We can see that there are two ways of passing these parameter values - "ByPropertyName" and "ByValue". </span><br /><span style="font-family: verdana,geneva; font-size: small;">Let&rsquo;s start with "By Value". As the name suggests, the value can be passed through the pipeline. That is, these two statements are equivalent..</span></p>
<p><br /><span style="font-family: verdana,geneva; font-size: small;">Start-Service -Name bits</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">"bits" | Start-Service</span></p>
<p><br /><span style="font-family: verdana,geneva; font-size: small;">where "bits" is the name of the service. Instead of passing value through the parameter, we passed the value through a pipeline as the parameter accepts pipeline input "by value". While piping, the datatype of the value was matched with the datatype of the parameter. The string datatype in this case matched with the datatype of the parameter &ldquo;Name&rdquo; and hence the statement was successful in starting the service named &ldquo;bits&rdquo;.</span><br /><span style="font-family: verdana,geneva; font-size: small;">Now let&rsquo;s look at other piece of the "Accepts Pipeline Input" - "By PropertyName". As the name suggests, we need to pass objects to the cmdlet and these objects should have property with the same name as the name of the parameter in the cmdlet. (This will be explained in the following example).</span></p>
<p><br /><span style="font-family: verdana,geneva; font-size: small;">That is, in our example, we need to have an object with a property "name" (same as parameter "Name") to pass to the Start-Service cmdlet There are multiple ways of creating objects or properties in PowerShell, but that is outside the scope of this blog post. </span><br /><span style="font-family: verdana,geneva; font-size: small;">Let&rsquo;s use the Import-CSV cmdlet to create an object having property called "Name". For that, we will create a service.csv file with the following text:</span></p>
<p><br /><span style="font-family: verdana,geneva; font-size: small;">name,description</span><br /><span style="font-family: verdana,geneva; font-size: small;">bits,description of the service</span></p>
<p><br /><span style="font-family: verdana,geneva; font-size: small;">Import-CSV on that file will give you the following output. An object has been created with "name" as one of its properties:</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"></span>&nbsp;</p>
<p><span style="font-family: verdana,geneva; font-size: small;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/6180.importcsv.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/6180.importcsv.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/6180.importcsv.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/6180.importcsv.png" border="0" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/5633.importcsv.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/5633.importcsv.png"></a></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;">To make it simpler, lets use Get-Member to check the properties of the object. Lets do&nbsp;Import-CSV proc.csv | Get-Member -MemberType *Property to list all the properties of the object:</span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/0118.importcsv_member.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/0118.importcsv_5F00_member.png"></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/8206.importcsv_member.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/8206.importcsv_5F00_member.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/54/81/8206.importcsv_member.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-54-81/8206.importcsv_5F00_member.png" border="0" /></a></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">We can see that an object exists with "name" as one of its properties. Now, we will pass this object to Start-Service cmdlet.</span><span style="color: black;"><o:p></o:p></span></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">Import-CSV service.csv | Start-Service</span><span style="color: black;"><o:p></o:p></span></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">Once we do that, we will see that the "bits" service is started. </span><span style="color: black;"><o:p></o:p></span></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">What happens behind the scenes is: the object generated from Import-CSV was passed to the Start-Service cmdlet. This object had a property called "name" which matched with the parameter called "Name" of Start-Service cmdlet. The property name had a value called "bits", therefore Start-Service started the "bits" service.</span><span style="color: black;"><o:p></o:p></span></span></p>
<p><span style="font-family: verdana,geneva; font-size: small;"><span style="color: black; mso-bidi-font-family: Arial;">Hopefully, these examples&nbsp;should have given you a good understanding of the fundamentals of pipeline in PowerShell.</span><span style="color: black;"><o:p></o:p></span></span></p>
<p><span style="color: black; font-family: verdana,geneva; font-size: small; mso-bidi-font-family: Arial;">See you in my next topic of PowerShell. Till then, keep scripting! :)</span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"><o:p></o:p></span></p>]]></content:encoded>
    </item>
  </channel>
</rss>