-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPnP Validation test.psm1
52 lines (43 loc) · 1.6 KB
/
PnP Validation test.psm1
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
function Add-CarandColorandOwner {
param(
[Parameter(Mandatory=$true)]
[string]$CarName,
[Parameter(Mandatory=$true)]
[ValidateScript({ $_ -in $(Get-ValidColorChoices)},ErrorMessage = 'Color not found')]
[ArgumentCompleter({Get-ValidColorChoices})]
[string]$Color,
[Parameter(Mandatory=$true)]
[ValidateScript({ $_ -in $(Get-ValidUserNames -AsObjects | Select-Object DisplayName -ExpandProperty DisplayName)},ErrorMessage = 'User not found')]
[ArgumentCompleter({
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
$users = Get-ValidUserNames -AsObjects
foreach ($user in $users) {
$completionText = "'{0}'" -f $user.DisplayName
$tooltip = $user.UserPrincipalName
$result = New-Object System.Management.Automation.CompletionResult $completionText, $tooltip, 'ParameterValue', $tooltip
$result
}
})]
[string]$Owner
)
$listName = "CarsandColorswithPeople"
$itemProperties = @{
"Title" = $CarName
"Color" = $Color
"Owner" = $Owner
}
Add-PnPListItem -List $listName -Values $itemProperties
Write-Host "Item added successfully"
}
function Get-ValidUserNames {
param(
[switch]$AsObjects
)
$Users = Get-PnPAzureADUser
if ($AsObjects) {
$ValidUserNames = $Users | Select-Object DisplayName, UserPrincipalName
} else {
$ValidUserNames = $Users.UserPrincipalName
}
return $ValidUserNames
}