Private/Get-IdoItCacheFile.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
60
61
62
63
Function Get-IdoItCacheFile {

    <#
   .SYNOPSIS
   Gets the content of a cache file in the users local app data directory

   .DESCRIPTION
   Gets the content of a cache file in the users local app data directory

   .PARAMETER CacheType
   CacheType defines wich type of cache to be written.

   .EXAMPLE
   PS> Gew-IdoItCacheFile -CacheType Constant

   This will the cache for idoit constants

   .NOTES
   Version
   0.1.0 20.01.2018 CB initial release
   #>


   [CmdletBinding ()]
   Param (
       [Parameter (
           Mandatory = $True
       )]
       [ValidateSet('Constant','Config')]
       [String]$CacheType
   )

   Begin {
           # $VerbosePreference = Continue
           $CachePath = $env:LOCALAPPDATA+"\.psidoit"
           $CacheFile = $CachePath + "\$CacheType.json"
           #CacheFile = $CachePath + "\Constant.json"


   }

   Process {
   # More work needed :-)
       Try {


        If ( (Test-Path $CacheFile ) ) {

            Return (Get-Content -Path $CacheFile -Raw -Encoding Default | ConvertFrom-Json).Data.Value

        }


       }
       Catch [Exeption] {

           Throw $_

       }

   }

}