Skip to content

Commit 536ad57

Browse files
committed
Added New-PSObject
1 parent 69679aa commit 536ad57

File tree

7 files changed

+141
-0
lines changed

7 files changed

+141
-0
lines changed

PowerShellScripts.psd1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ NestedModules = @(
134134
'.\Utils\Invoke-Parser.ps1',
135135
'.\Utils\Migrate-ScheduledTask.ps1',
136136
'.\Utils\Monitor-Folder.ps1',
137+
'.\Utils\New-PSObject.ps1',
137138
'.\Utils\Open-Registry.ps1',
138139
'.\Utils\Restart-Process.ps1'
139140
)
@@ -253,6 +254,9 @@ PrivateData = @{
253254

254255

255256

257+
258+
259+
256260

257261

258262

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Some PowerShell scipts that can be hopefully also useful to others. Most of them
6262
| Invoke-Parser | Utils\Invoke-Parser.ps1 | Uses PowerShell's parser and returns the AST, Tokens and Errors | | [Link](https://github.com/DBremen/PowerShellScripts/blob/master/docs/Invoke-Parser.md) |
6363
| Migrate-ScheduledTask | Utils\Migrate-ScheduledTask.ps1 | Script to migrate scheduled tasks from Windows XP/Server 2003 to Windows 7/Server 2008 task scheduler | | [Link](https://github.com/DBremen/PowerShellScripts/blob/master/docs/Migrate-ScheduledTask.md) |
6464
| Monitor-Folder | Utils\Monitor-Folder.ps1 | Monitors a folder for changes using non-persistent asynchronous events | | [Link](https://github.com/DBremen/PowerShellScripts/blob/master/docs/Monitor-Folder.md) |
65+
| New-PSObject | Utils\New-PSObject.ps1 | Helper function to create PSCustomObjects based on array of names and array of properties. | | [Link](https://github.com/DBremen/PowerShellScripts/blob/master/docs/New-PSObject.md) |
6566
| Open-Registry | Utils\Open-Registry.ps1 | Open the regedit at the specified path similar to sysinternals regjump. | | [Link](https://github.com/DBremen/PowerShellScripts/blob/master/docs/Open-Registry.md) |
6667
| Restart-Process | Utils\Restart-Process.ps1 | Function to restart process(es) | [Link](https://powershellone.wordpress.com/2016/02/25/fix-clipboard-is-not-working-restart-process-with-powershell/) | [Link](https://github.com/DBremen/PowerShellScripts/blob/master/docs/Restart-Process.md) |
6768
| Generate-ScriptMarkdownHelp | PowerShellScripts\Generate-ScriptMarkdownHelp.ps1 | The function that generated the Markdown help in this repository. (see Example for usage). Generates markdown help for Github for each function containing comment based help (Description not empty) within a folder recursively and a summary table for the main README.md | | [Link](https://github.com/DBremen/PowerShellScripts/blob/master/docs/Generate-ScriptMarkdownHelp.md) |

Utils/New-PSObject.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function new-pscustomobject ([string[]] $names , [object[]] $values ){
2+
$obj = 1| select-object $names
3+
0..($names.length-1) | % {
4+
$obj.$($names[$_]) = $values[$_]
5+
}
6+
$obj
7+
}
8+
9+
function New-PSObject{
10+
<#
11+
.SYNOPSIS
12+
Helper function to create PSCustomObjects based on array of names and array of properties.
13+
.DESCRIPTION
14+
Enables rapid creation of PSCustomObjects
15+
.PARAMETER PropertyNames
16+
An array of property names
17+
.PARAMETER Values
18+
The values to be assigned to the properties in the same order as the property names
19+
.EXAMPLE
20+
$props= echo City Country CurrencySymbol
21+
$result = & {
22+
new-psobject $props Berlin Germany EUR
23+
new-psobject $props Zurich Switzerland CHF
24+
}
25+
$result
26+
#>
27+
[CmdletBinding()]
28+
param(
29+
[Parameter(Mandatory,
30+
Position = 0)]
31+
[array]$PropertyNames,
32+
[Parameter(Mandatory,ValueFromRemainingArguments,
33+
Position = 1)]$Values
34+
)
35+
$ht = [ordered]@{}
36+
$i = 0
37+
foreach ($prop in $PropertyNames){
38+
$ht.Add($prop,$Values[($i++)])
39+
}
40+
[PSCustomObject]$ht
41+
}
42+
43+

docs/Clear-Clipboard.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ Clear-Clipboard
9595

9696

9797

98+
99+
100+
98101

99102

100103

docs/Get-ACEData.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ v1.0 - Chad Miller - 4/21/2011 - Initial release
288288
289289
290290
291+
292+
293+
294+
295+
296+
297+
298+
299+
291300
292301
293302

docs/Get-LegacyHelp.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ Accept wildcard characters: False
279279
280280
281281
282+
283+
284+
285+
286+
287+
288+
289+
290+
282291
283292
284293

docs/New-PSObject.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# New-PSObject
2+
3+
## SYNOPSIS
4+
Helper function to create PSCustomObjects based on array of names and array of properties.
5+
6+
## Script file
7+
Utils\New-PSObject.ps1
8+
9+
## SYNTAX
10+
11+
```
12+
New-PSObject [-PropertyNames] <Array> [-Values] <Object>
13+
```
14+
15+
## DESCRIPTION
16+
Enables rapid creation of PSCustomObjects
17+
18+
## EXAMPLES
19+
20+
### -------------------------- EXAMPLE 1 --------------------------
21+
```
22+
$props= echo City Country CurrencySymbol
23+
24+
25+
$result = & {
26+
new-psobject $props Berlin Germany EUR
27+
new-psobject $props Zurich Switzerland CHF
28+
}
29+
$result
30+
```
31+
## PARAMETERS
32+
33+
### -PropertyNames
34+
An array of property names
35+
36+
```yaml
37+
Type: Array
38+
Parameter Sets: (All)
39+
Aliases:
40+
41+
Required: True
42+
Position: 1
43+
Default value: None
44+
Accept pipeline input: False
45+
Accept wildcard characters: False
46+
```
47+
48+
### -Values
49+
The values to be assigned to the properties in the same order as the property names
50+
51+
```yaml
52+
Type: Object
53+
Parameter Sets: (All)
54+
Aliases:
55+
56+
Required: True
57+
Position: 2
58+
Default value: None
59+
Accept pipeline input: False
60+
Accept wildcard characters: False
61+
```
62+
63+
## INPUTS
64+
65+
## OUTPUTS
66+
67+
## NOTES
68+
69+
## RELATED LINKS
70+
71+
72+

0 commit comments

Comments
 (0)