{"id":3969,"date":"2013-03-25T00:01:00","date_gmt":"2013-03-25T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/03\/25\/learn-about-using-powershell-value-binding-by-property-name\/"},"modified":"2013-03-25T00:01:00","modified_gmt":"2013-03-25T00:01:00","slug":"learn-about-using-powershell-value-binding-by-property-name","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/learn-about-using-powershell-value-binding-by-property-name\/","title":{"rendered":"Learn About Using PowerShell Value Binding by Property Name"},"content":{"rendered":"<p><strong>Summary<\/strong>: &nbsp;Guest blogger, Ingo Karstein, talks about using Windows PowerShell and value binding by property name.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today our blog is written by Ingo Karstein who has shared his knowledge previously with us. Ingo is an independent consultant for SharePoint and Windows PowerShell based in Leipzig, Germany and a Microsoft Certified Master for SharePoint 2010.<\/p>\n<ul>\n<li>Ingo&rsquo;s blog: <a href=\"http:\/\/blog.karstein-consulting.com\/\" target=\"_blank\">Karstein Consulting<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/ingo+karstein\/\" target=\"_blank\">Ingo&rsquo;s previous posts<\/a> on the Hey, Scripting Guy! Blog<\/li>\n<\/ul>\n<p>Take it away, Ingo&hellip;<\/p>\n<p>Do you know about value binding by property name in Windows PowerShell pipelines and what it is good for? I&rsquo;d like to explain it to you!<\/p>\n<p>First, what is value binding? In a Windows PowerShell pipeline context, it is possible to transfer (pipe) objects from one cmdlet to another.<\/p>\n<p>Here is a simple example:<\/p>\n<p>You can use <strong>Get-Process<\/strong> <strong>IExplore<\/strong> to retrieve all Internet Explorer processes as .NET objects. With the cmdlet <strong>Stop-Process<\/strong>, you can stop processes. A WindowsPowerShell pipeline connects both cmdlets. By piping the Internet Explorer objects from <strong>Get-Process<\/strong> to <strong>Stop-Process<\/strong>, you can stop the processes.<\/p>\n<p style=\"padding-left: 30px\">Get-Process &#8220;IExplore&#8221; | Stop-Process<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3312.hsg-3-25-13-1.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3312.hsg-3-25-13-1.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>When you use this command, you are using a Windows PowerShell pipeline marked by the pipe character ( <strong>|<\/strong> ), and you use value binding. The <strong>Stop-Process<\/strong> cmdlet has a parameter called <strong>InputObject<\/strong>, which accepts process objects to do its work. You could also use a variable to specify the <strong>InputObject <\/strong>parameter.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8228.hsg-3-25-13-2.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8228.hsg-3-25-13-2.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>The example in the previous screenshot shows an explicit value binding of the <strong>$ie<\/strong> variable to the <strong>InputObject<\/strong> parameter. The Windows PowerShell pipeline does exactly the same, but implicitly! It takes one or more objects from <strong>Get-Process<\/strong> and tries to bind them to some parameter of the <strong>Stop-Process<\/strong> cmdlet. &ldquo;Some parameter&rdquo; means that Windows PowerShell analyzes the cmdlet and its parameters, and if a parameter&rsquo;s data type matches the given object&rsquo;s data type, it binds the object to the parameter and runs the command.<\/p>\n<p>The following image shows a look into the Windows PowerShell internal Help for <strong>Stop-Process<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4278.hsg-3-25-13-3.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4278.hsg-3-25-13-3.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>You can see that the <strong>InputObject<\/strong> parameter accepts an array (marked by &ldquo;<strong>[ ]<\/strong>&rdquo;) of <strong>Process<\/strong> objects through the pipeline by using&nbsp;<strong>ByValue<\/strong>.<\/p>\n<p>Now let&rsquo;s get closer to the main topic of this blog post: Value binding by property name.<\/p>\n<p>Let&rsquo;s have a look at another parameter of <strong>Get-Process<\/strong> called <strong>Name<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8468.hsg-3-25-13-4.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8468.hsg-3-25-13-4.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Like the <strong>InputObject<\/strong> parameter, <strong>Name<\/strong> also accepts pipeline input, but by using&nbsp;<strong>ByPropertyName<\/strong> instead of <strong>ByValue<\/strong> as in the previous screenshot.<\/p>\n<p>Now let&rsquo;s try to run the command first with an explicit data-type string value for the <strong>Name<\/strong> parameter. This works as expected.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1425.hsg-3-25-13-5.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1425.hsg-3-25-13-5.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Now we try to bind the string value <strong>IExplore<\/strong> to the parameter by using a Windows PowerShell pipeline.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1007.hsg-3-25-13-6.png\"><img decoding=\"async\" title=\"Image of error message\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1007.hsg-3-25-13-6.png\" alt=\"Image of error message\" \/><\/a><\/p>\n<p>This presents an error message because there is no parameter for the <strong>Stop-Process<\/strong> cmdlet that accepts string (or array of strings) data as <strong><span style=\"text-decoration: underline\">ByValue<\/span><\/strong> pipeline input.<\/p>\n<p>So how can we use the pipeline binding for the <strong>Name<\/strong> parameter that is marked with&nbsp;<strong>ByPropertyName<\/strong>? Let&rsquo;s say we have a certain object that has a property called <strong>Name<\/strong> like the following object:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0336.hsg-3-25-13-7.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0336.hsg-3-25-13-7.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>The object in the <strong>$myObject<\/strong> variable has only one property (<strong>Name<\/strong>) with the <strong>IExplore<\/strong> value.<\/p>\n<p>Now we can use this object as pipeline input.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7140.hsg-3-25-13-8.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7140.hsg-3-25-13-8.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>No error message here! The pipeline engine of Windows PowerShell does a lot of simple magic here. It tries to match all properties of the input object to the cmdlet. This match is done by name. The input object in the example has a <strong>Name<\/strong> property&nbsp;of the type <strong>String<\/strong>, and the <strong>Stop-Process<\/strong> cmdlet has a <strong>Name<\/strong> parameter&nbsp;that accepts <strong>String<\/strong> values. This is a perfect match!<\/p>\n<p>The match also works if the input object has more properties.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0383.hsg-3-25-13-9.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0383.hsg-3-25-13-9.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>When you run <strong>$myObject | Stop-Process<\/strong> again, it will also match the <strong>Name<\/strong> property and the <strong>Name<\/strong> parameter. But it does not work for an object that has no <strong>Name<\/strong> property.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2161.hsg-3-25-13-10.png\"><img decoding=\"async\" title=\"Image of error message\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2161.hsg-3-25-13-10.png\" alt=\"Image of error message\" \/><\/a><\/p>\n<p>Here is how I created the object in the <strong>$myObject<\/strong> variable:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2625.hsg-3-25-13-11.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2625.hsg-3-25-13-11.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>I created a new empty Windows PowerShell object by using <strong>New-Object System.Management.Automation.Object<\/strong>, and I added some properties by using the <strong>Add-Member<\/strong> cmdlet. This is a very cool feature in Windows PowerShell that allows you to create custom objects on the fly and work with them.<\/p>\n<p>Now a more complex example&hellip;<\/p>\n<p>Let&rsquo;s say you want to import some plain text log files into Windows PowerShell. For each log file, you want to specify the file name <strong>plus<\/strong> the number of lines you want to read from the beginning of the file <strong>or<\/strong> the number of lines to read from the end of the file. You could use the following.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4214.hsg-3-25-13-12.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4214.hsg-3-25-13-12.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Following is the Help information about <strong>Get-Content<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7103.hsg-3-25-13-13.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7103.hsg-3-25-13-13.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>As you can see, three parameters can be bound by <strong>Property<\/strong> name. If you have a certain objects with corresponding <strong>Property<\/strong> names, you can pass these objects to the cmdlet and bind the parameters to the object values.<\/p>\n<p>Let&rsquo;s create some objects:<\/p>\n<p style=\"padding-left: 30px\">$log1 = New-Object System.Management.Automation.PSObject<\/p>\n<p style=\"padding-left: 30px\">$log1 | Add-Member -Name &#8220;Path&#8221; -Value &#8220;Log1.txt&#8221; -MemberType NoteProperty<\/p>\n<p style=\"padding-left: 30px\">$log1 | Add-Member -Name &#8220;TotalCount&#8221; -Value 3 -MemberType NoteProperty<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">$log2 = New-Object System.Management.Automation.PSObject<\/p>\n<p style=\"padding-left: 30px\">$log2 | Add-Member -Name &#8220;Path&#8221; -Value &#8220;Log2.txt&#8221; -MemberType NoteProperty<\/p>\n<p style=\"padding-left: 30px\">$log2 | Add-Member -Name &#8220;TotalCount&#8221; -Value 5 -MemberType NoteProperty<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">$log3 = New-Object System.Management.Automation.PSObject<\/p>\n<p style=\"padding-left: 30px\">$log3 | Add-Member -Name &#8220;Path&#8221; -Value &#8220;Log3.txt&#8221; -MemberType NoteProperty<\/p>\n<p style=\"padding-left: 30px\">$log3 | Add-Member -Name &#8220;Tail&#8221; -Value 2 -MemberType NoteProperty<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">$log4 = New-Object System.Management.Automation.PSObject<\/p>\n<p style=\"padding-left: 30px\">$log4 | Add-Member -Name &#8220;Path&#8221; -Value &#8220;Log4.txt&#8221; -MemberType NoteProperty<\/p>\n<p style=\"padding-left: 30px\">$log4 | Add-Member -Name &#8220;Tail&#8221; -Value 4 -MemberType NoteProperty<\/p>\n<p>This is how they look:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8176.hsg-3-25-13-14.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8176.hsg-3-25-13-14.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Now you can use them together as pipeline input. The pipeline engine will always match the corresponding properties and parameters by their names.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6825.hsg-3-25-13-15.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6825.hsg-3-25-13-15.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>The command <strong>@($log1, $log2, $log3, $log4) | Foreach-Object { $_ | Get-Content }<\/strong> looks strange, doesn&rsquo;t it? If you try to run <strong>@($log1, $log2, $log3, $log4) | Get-Content<\/strong>, you will see that it fails for the objects in variables <strong>$log3<\/strong> and <strong>$log4<\/strong> because <strong>Get-Content<\/strong> does not allow the <strong>TotalCount <\/strong>and <strong>Tail<\/strong> parameters side-by-side.<\/p>\n<p>You might say <strong>$log3<\/strong> and <strong>$log4<\/strong> do not have a <strong>TotalCount<\/strong> property. You are correct! But through the first two objects, <strong>$log1<\/strong> and <strong>$log2<\/strong>, the pipeline engine expects that all pipeline input objects will have at least two properties: <strong>Path<\/strong> and <strong>TotalCount<\/strong>. For <strong>$log3<\/strong> and <strong>$log4<\/strong>, it finds one additional input parameter, called <strong>Tail<\/strong>, which theoretically can be bound by property name.<\/p>\n<p>It tries to bind the already known <strong>TotalCount<\/strong> property with a value of <strong>$null<\/strong>, and the new <strong>Tail<\/strong> property with a real value at the same time. That fails because <strong>Tail<\/strong> and <strong>TotalCount<\/strong> cannot coexist in one call. In the previous screenshot, all objects are piped to the <strong>Get-Content<\/strong> cmdlet separately.<\/p>\n<p>One step further&hellip;<\/p>\n<p>I am writing this blog because I used value binding by property name in a Windows PowerShell project about importing and exporting design packages. For more information, see:<\/p>\n<ul>\n<li><a href=\"http:\/\/blog.karstein-consulting.com\/2013\/02\/18\/sharepoint-2013-design-packages-import-with-powershell-part-2-of-2\/\" target=\"_blank\">SharePoint 2013 Design Packages: Import with PowerShell<\/a><\/li>\n<li><a href=\"http:\/\/blog.karstein-consulting.com\/2013\/02\/14\/sharepoint-2013-design-packages-export-with-powershell-part-1-of-2\/\" target=\"_blank\">SharePoint 2013 Design Packages: Export with PowerShell<\/a><\/li>\n<\/ul>\n<p>In those scripts, I wanted to call Windows PowerShell <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/hh847872.aspx\" target=\"_blank\">Cmdlet Binding<\/a>-enabled functions by using hash tables. I wanted to bind named hash table items to cmdlet parameter names. The following example shows an array of four hash tables.<\/p>\n<p style=\"padding-left: 30px\">@(<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; @{ Path=&#8221;Log1.txt&#8221;; TotalCount=3 },<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; @{ Path=&#8221;Log2.txt&#8221;; TotalCount=5 },<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; @{ Path=&#8221;Log3.txt&#8221;; Tail=4 },<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; @{ Path=&#8221;Log4.txt&#8221;; Tail=2 }<\/p>\n<p style=\"padding-left: 30px\">)<\/p>\n<p>I want to use them as pipeline input for the <strong>Get-Content<\/strong> cmdlet, but as you can see, it does not work. There is no cmdlet parameter for <strong>Get-Content<\/strong> that accepts a hash table as input.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1261.hsg-3-25-13-16.png\"><img decoding=\"async\" title=\"Image of error message\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1261.hsg-3-25-13-16.png\" alt=\"Image of error message\" \/><\/a><\/p>\n<p>Therefore, I created a function that enables this scenario by creating objects out of hash tables. Here I use the <strong>Add-Member<\/strong> cmdlet as shown earlier.<\/p>\n<p style=\"padding-left: 30px\">function New-ObjectFromHashtable {<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [CmdletBinding()]<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param(<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true)]<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Hashtable]<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Hashtable<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin { }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; process {<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r = new-object System.Management.Automation.PSObject<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Hashtable.Keys | % {<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; $key=$_<\/p>\n<p style=\"padding-left: 30px\">&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=$Hashtable[$key]<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&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; $r | Add-Member -MemberType NoteProperty -Name $key -Value $value -Force<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end { }<\/p>\n<p style=\"padding-left: 30px\">}<\/p>\n<p>This takes hash tables as pipeline input. For each hash table in the pipeline, the function creates a new object. For each key in the hash table, the function adds a property to the object and sets the value of the property to the value of the hash table item referenced by the key. The result is a list of objects. The function itself can be used in a pipeline.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7217.hsg-3-25-13-17.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7217.hsg-3-25-13-17.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>I hope you will find this function useful in your own scripts when you want to utilize pipeline binding by property name to set multiple cmdlet parameter values at once.<\/p>\n<p>Thanks for reading!<\/p>\n<p>~Ingo<\/p>\n<p>Thank you Ingo! This excellent blog should prove to be immediately valuable to many of the readers. Join me tomorrow when I will talk about more cool stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: &nbsp;Guest blogger, Ingo Karstein, talks about using Windows PowerShell and value binding by property name. Microsoft Scripting Guy, Ed Wilson, is here. Today our blog is written by Ingo Karstein who has shared his knowledge previously with us. Ingo is an independent consultant for SharePoint and Windows PowerShell based in Leipzig, Germany and a [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,274,3,4,45],"class_list":["post-3969","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-ingo-karstein","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: &nbsp;Guest blogger, Ingo Karstein, talks about using Windows PowerShell and value binding by property name. Microsoft Scripting Guy, Ed Wilson, is here. Today our blog is written by Ingo Karstein who has shared his knowledge previously with us. Ingo is an independent consultant for SharePoint and Windows PowerShell based in Leipzig, Germany and a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3969","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=3969"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3969\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=3969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}