-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUpdate-PrinterMap.ps1
More file actions
104 lines (96 loc) · 2.53 KB
/
Copy pathUpdate-PrinterMap.ps1
File metadata and controls
104 lines (96 loc) · 2.53 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Param(
# Map file to verify, template at
$map = "\\bhs-app01\Deployment\printer\map.json"
, # output path
$validpath = "\\bhs-app01\Deployment\printer\valid-print-map"
, # Output a template map file. Pipe to out-file "mymap.json"
[switch]$GetTemplate
)
$template= @'
{
"Server":[
{
"Name": "org-server1",
"Room":[
{
"name": "roomA",
"share": [
{
"Name": "printer1",
"Default": true
},
{
"Name": "printer2"
}
]
}
],
"Computer":[
{
"name": "labA1",
"share": [
{
"Name": "printer3"
}
]
}
],
"User":[
{
"Name": "example",
"share": [
{
"Name": "printer1"
}
]
}
]
},
{
"Name": "org-server2",
"Computer": [
{
"name": "LabA1",
"share": [
{
"Name": "printer1"
}
]
}
]
}
]
}
'@
if($GetTemplate){
Write-warning "Pipe this to | out-file mymap.json"
write-output $template
return
}
function create{
Param(
[string]$in,
[string]$out
)
Get-Content -Raw -path $in |
ConvertFrom-Json |
ConvertTo-Json -depth 100 |
Out-File -FilePath $out -Encoding 'utf8' -force
}
$file = get-item $map -errorAction Stop
try{
$output = Get-item $validPath
} catch {
$new = $True
}
# Convert from json and back to json to confirm powershell doesn't have any error reading the format.
if($new){
write-warning "No file found, creating new at $validpath"
create -in $file.fullname -out $validPath
}
if($file.LastWriteTimeUtc -gt $output.LastWriteTimeUtc){
write-warning "Map file newer than validated file, updating at $validpath"
create -in $file.fullname -out $output.fullname
} else {
write-warning "Map last write date is not newer than the validated file."
}