-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManage-ITSSInTrustRepositories.ps1
59 lines (57 loc) · 2.81 KB
/
Manage-ITSSInTrustRepositories.ps1
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
53
54
55
56
57
58
59
Param([string]$action="List",[string]$servername="localhost",[parameter(
Mandatory = $false,
ValueFromPipeline = $true)]$repository,$creds)
begin{
try{$res=add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
}
catch{}
$newselectedreps=""
$newrepositorylist=""
}
process{
ForEach ($input in $repository) {
$newrepositorylist+=";"+$input.Id
$newselectedreps+=",{Name:"""+$input.Name+""",Id:"""+$input.Id+"""}"
}
}
end{
#if($creds){}
#else{$creds=Get-Credential}
switch($action)
{
List{
Invoke-RestMethod -method GET -Uri https://$servername/api/1.0/settings -UseDefaultCredentials | select -expand connectors| select -expand InTrust | select -expand parameters | select -expand selectedReps
}
Search{
Invoke-RestMethod -method PUT -Uri https://$servername/api/1.0/connectors/InTrust/repositories -UseDefaultCredentials | select -expand repositories
}
Add{
if($repository)
{
$repositorylist=Invoke-RestMethod -method GET -Uri https://$servername/api/1.0/settings -UseDefaultCredentials | select -expand connectors| select -expand InTrust | select -expand parameters | select -expand repository
$selectedreps= Invoke-RestMethod -method GET -Uri https://$servername/api/1.0/settings -UseDefaultCredentials | select -expand connectors| select -expand InTrust | select -expand parameters | select -expand selectedReps
$repositorylist=$repositorylist+$newrepositorylist
$selectedreps=$selectedreps.Replace("]",$newselectedreps+"]")
$InTrustConnectorSettings=@{repository=$repositorylist;selectedReps=$selectedreps} | ConvertTo-Json
$body="{connectors:{InTrust:{parameters:{repository:"""+$repositorylist+""",selectedReps:"+$selectedreps+"}}}}"
#$body
Invoke-RestMethod -method PUT -Body $body -Uri https://$servername/api/1.0/settings -UseDefaultCredentials
}
}
Remove{
echo "Not Implemented"
}
default{Invoke-RestMethod -method GET -Uri https://$servername/api/1.0/settings -UseDefaultCredentials | select -expand connectors| select -expand InTrust | select -expand parameters | select -expand selectedReps}
}
}