-
Notifications
You must be signed in to change notification settings - Fork 0
/
win_file.ps1
54 lines (43 loc) · 892 Bytes
/
win_file.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
#!powershell
# WANT_JSON
# POWERSHELL_COMMON
$params = Parse-Args $args;
$result = New-Object psobject @{
win_file = New-Object psobject
changed = $false
}
$content = ""
if ($params.content) {
$content = $params.content
}
if ($params.mkdir) {
mkdir $params.mkdir
$params.file = $params.mkdir + $params.file
}
switch ($params.action) {
"delete" {
Try {
rm $params.file
Set-Attr $result.win_file $params.file "deleted"
$result.changed = $true
}
Catch {
echo $Error
Fail-Json $result "Error deleting file"
}
}
"update" {
set-content $params.file $content
}
default {
Try {
new-item $params.file -value $content -itemtype file
$result.changed = $true
Set-Attr $result.win_file $params.file "created"
}
Catch {
Fail-Json $result "Error creating file"
}
}
}
Exit-Json $result;