forked from teppeiy/AzureAD-Tips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportADFSApps_v4.ps1
59 lines (47 loc) · 1.9 KB
/
ExportADFSApps_v4.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
# For PowerShell version below 5
<#
.DISCLAIMER
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) Microsoft Corporation. All rights reserved.
#>
Function Remove-InvalidFileNameChars
{
param(
[Parameter(Mandatory=$true,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[String]$Name
)
$invalidChars = [IO.Path]::GetInvalidFileNameChars() -join ''
$re = "[{0}]" -f [RegEx]::Escape($invalidChars)
return ($Name -replace $re)
}
$filePathBase = "C:\ADFS\apps\"
$zipfileBase = "c:\ADFS\zip\"
$zipfileName = $zipfileBase + "ADFSApps.zip"
mkdir $filePathBase -ErrorAction SilentlyContinue
mkdir $zipfileBase -ErrorAction SilentlyContinue
$AdfsRelyingPartyTrusts = Get-AdfsRelyingPartyTrust
foreach ($AdfsRelyingPartyTrust in $AdfsRelyingPartyTrusts)
{
$RPfileName = $AdfsRelyingPartyTrust.Name.ToString()
$CleanedRPFileName = Remove-InvalidFileNameChars -Name $RPfileName
$RPName = "RPT - " + $CleanedRPFileName
$filePath = $filePathBase + $RPName + '.xml'
$AdfsRelyingPartyTrust | Export-Clixml $filePath -ErrorAction SilentlyContinue
}
$AdfsClaimsProviderTrusts = Get-AdfsClaimsProviderTrust
foreach ($AdfsClaimsProviderTrust in $AdfsClaimsProviderTrusts)
{
$CPfileName = $AdfsClaimsProviderTrust.Name.ToString()
$CleanedCPFileName = Remove-InvalidFileNameChars -Name $CPfileName
$CPTName = "CPT - " + $CleanedCPFileName
$filePath = $filePathBase + $CPTName + '.xml'
$AdfsClaimsProviderTrust | Export-Clixml $filePath -ErrorAction SilentlyContinue
}
#Compress-Archive -Path $filePathBase -DestinationPath $zipfileName
invoke-item $filePathBase