-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathNewInstallerDirectoryCommand.cs
52 lines (47 loc) · 2.12 KB
/
NewInstallerDirectoryCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Linq;
using System.Management.Automation;
namespace PSMSI
{
[Cmdlet(VerbsCommon.New, "InstallerDirectory", DefaultParameterSetName = "custom")]
public class NewInstallerDirectoryCommand : PSCmdlet
{
[Parameter(Mandatory = true, ParameterSetName = "custom", Position = 0)]
public string DirectoryName { get; set; }
[Parameter(Mandatory = true, ParameterSetName = "predefined")]
[ValidateSet("AdminToolsFolder", "AppDataFolder", "CommonAppDataFolder", "CommonFilesFolder", "CommonFiles64Folder", "CommonFiles6432Folder", "DesktopFolder", "FavoritesFolder", "FontsFolder", "LocalAppDataFolder", "MyPicturesFolder", "PersonalFolder", "ProgramFilesFolder", "ProgramFiles64Folder", "ProgramFiles6432Folder", "ProgramMenuFolder", "SendToFolder", "StartMenuFolder", "StartupFolder", "SystemFolder", "System64Folder", "TemplateFolder", "WindowsFolder")]
public string PredefinedDirectoryName { get; set; }
[Parameter(ParameterSetName = "custom")]
public string Id { get; set; }
[Parameter(Position = 1)]
public ScriptBlock Content { get; set; }
[Parameter(ParameterSetName = "custom")]
public SwitchParameter Configurable { get; set; }
protected override void ProcessRecord()
{
if (ParameterSetName == "custom")
{
if (!MyInvocation.BoundParameters.ContainsKey("Id"))
{
Id = "dir" + Guid.NewGuid().ToString("n");
}
WriteObject(new Models.Directory
{
Name = DirectoryName,
Id = Id,
Content = Content?.Invoke().Select(m => m.BaseObject),
Configurable = Configurable
});
}
else
{
WriteObject(new Models.Directory
{
Name = PredefinedDirectoryName,
Id = PredefinedDirectoryName,
Content = Content?.Invoke().Select(m => m.BaseObject)
});
}
}
}
}