Today in my PowerShell class, we are utilizing custom properties to allow us to create user accounts in mass. In our scenario, we have a CSV that contains everything that we need except a property called “Name”. We are using Select-Object to grab information from another property in the CSV to create our “Name” property.
To do this we have to type some cryptic code. To make life easier, I’m sending my class the procedure below. It will inject a new ISE Snippet that will create an easy to use template to create a custom property with Select-Object.
1. Create a new PowerShell script with the below line. Do not be concerned if there are any errors.
@{N="##PropertyName##";E={$_.##PropertyValue##}} |
2. Save this script.
3. Create a new script in the ISE with the code below.
$Text = (Get-Content -Raw -Path "E:\PowerShell\SOHash.ps1")
$Props = @{ "Title" = "Select-Object Custom Property"; "Description" = "Template to use with Select-Object to add a custom Property"; "Author" = "Jason A. Yoder" "Text" = $Text
}
New-IseSnippet @Props |
4. Replace my path in line 1 with the path to the saved script from step 2.
5. Press Ctrl-J in the ISE when you need to create a custom property while using Select-Object.
Comments