分類: Microsoft

Skype 8 Install with Windows 10 LTSB.

先來說說Windows版本

Windows 10 之前用的有三種版本

Windows Insider Preview Branch

Current Branch (for Business)(CB/CBB)

Long Term Servicing Branch(LTSB)

一般人裝的大都是Current Branch(CB)較多。

從1703開始,微軟推出Windows as a Service概念 Semi-Annual Channel,取代了CB和CBB的版本分支

然後Long Term Servicing Channel(LTSC)取代Long Term Servicing Branch(LTSB)

Windows Insider Preview Branch > Semi-Annual Channel(Target)

Current Branch (for Business)(CB/CBB) > Semi-Annual Channel

Long Term Servicing Branch(LTSB) > Long Term Servicing Channel(LTSC)

Windows 10的版本編號從最早的1507(RTM) > 1511 > 1607 > 1703 > 1709(Now)

用下面我自製的圖表大致說明這一些東西⊕為目前官方建議版本

 服務代號 1507 1511 1607 1703 1709 1803 1809
Semi-Annual Channel(Target)
Semi-Annual Channel
CB
CBB
LTSB

當然每個版本裡面還有細部編號下面是目前該本最新的

服務代號 最新版本編號
Semi-Annual Channel(Target) 16299.334
Semi-Annual Channel 16299.334
CB 15063.994
CBB 14393.2155
LTSB(LTSC) 14393.2155

所有的分支版本都有18個月的維護期。

廢話不多說,我們公司是安裝LTSB(LTSC)版本

LTSB(LTSC)版本一般來說不是給人使用的,通常是Kiosk這類的特定用途機器在使用,例如:自助服務、ATM

LTSB(LTSC)不會有功能性更新,同時也少了以下軟體

Microsoft Edge, Windows Store client, Cortana , Microsoft Mail, Calendar, OneNote, Weather, News, Sports, Money, Photos, Camera, Music, and Clock

我會講這麼多,其實只有一個重點

Windows 10 LTSB(LTSC)想裝新架構的Skype 8.X(官方下載),必須使用相容模式至Windows 7/8

因為Skype 8.X版本預設是從Microsoft Store裡面找的,所以正常安裝的時候,他會要求你去安裝Microsoft Store。

然後接著就卡關了,LTSB(LTSC)不會有也不能安裝Microsoft Store(正常情況下)

不然就屈就於現實,只能下載傳統版了官方最終版至7.40.0.10X

如果就是很想裝新版的,或是舊版的一直有問題想用新版的試試看怎麼辦呢?

重點來了:

1.下載來的安裝檔按右鍵內容

2.相容性模式打勾,選Windows 7 / 8

3.直接執行不要使用Run as Administrators,有跳出來叫你打管理員帳號密碼再打就好了。

好了,打完收工。

其實新版的Skype蠻美的!跟舊版的完全不一樣。

Please follow and like us:

用Powershell備份自己的電腦的資料

對於IT系統,備份是很重要滴!

當然對於IT人,IT人的個人電腦備份也是用重要的。

其實我最重要的是一顆256G的隨身碟,沒有它我就不知道怎麼上班了。

我這顆隨身碟裡面的部分重要資料是必須定時複寫其他兩顆隨身碟和一顆外接硬碟。

所以整個備份流程,我個人用三顆隨身碟+一顆外接硬碟來做備份。

說明一下程式的大概流程:

首先所有的備份動作都盡可能地會寫入Log按照月份分開

同時也會寫入本機的Windows Log裡面。

如果是用自帶的Function Logwrite,那就是寫入本機的文字檔。

如果是用Write-EventLog,那就是寫入系統的EventLog裡面。

所以如果扣掉寫Log,其實程式碼不多,這只是當時我想試驗一下這些功能而已。

接下來的程式碼會把寫Log部份抽離,這樣版面比較乾淨。

1
2
3
4
5
6
7
8
9
10
[String]$Logfile = "D:\BatchFile\Backuplog$yymm.txt" #LogFile
[String]$loginfo = "[INFO]"
[String]$logwarn = "[WARN]"
[String]$logerr = "[ERR ]"

Function LogWrite
{
Param([string]$logstring)
Add-content $Logfile "$(Get-date -Format 'yyyy-MM-dd tthh:mm:ss') $logstring"
}

本機電腦因為有C / D,所以偵測隨身碟的動作,只有到E/F/G/H/I/J/Z這些磁碟機代號跟目錄去搜尋一個特定文字檔是否存在,透過Foreach我很方便只要在這裡增加我想要的磁碟機代號即可。

這是利用迴圈下去找的,看起來繁瑣,但是執行效率還不錯,至少我不需要去管說到底現在哪顆隨身碟是在哪一個磁碟機代號。

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
$DetectDrvs = "E:","F:","G:","H:","I:","J:","Z:"
Foreach ($DetectDrv1 in $DetectDrvs)
{
[Bool]$Chkdrv1 = Test-Path "$DetectDrv1\Neo1.txt"
IF ($Chkdrv1 -eq $True)
{
$Drv1 = $DetectDrv1
Break
}
ELSE
{
$Drv1="NA"
}
}
Foreach ($DetectDrv2 in $DetectDrvs)
{
[Bool]$Chkdrv2 = Test-Path "$DetectDrv2\Neo2.txt"
IF ($Chkdrv2 -eq $True)
{
$Drv2 = $DetectDrv2
Break
}
ELSE
{
$Drv2="NA"
}
}
Foreach ($DetectDrv3 in $DetectDrvs)
{
[Bool]$Chkdrv3 = Test-Path "$DetectDrv3\Neo3.txt"
IF ($Chkdrv3 -eq $True)
{
$Drv3 = $DetectDrv3
Break
}
ELSE
{
$Drv3="NA"
}
}
Foreach ($DetectDrv4 in $DetectDrvs)
{
[Bool]$Chkdrv4 = Test-Path "$DetectDrv4\Neo2T.txt"
IF ($Chkdrv4 -eq $True)
{
$Drv4 = $DetectDrv4
Break
}
ELSE
{
$Drv4="NA"
}

接下來是一海票的變數定義

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
#-------------------------code-by-Neo-----------------------------------
[int]$Expireday = 10 #想要之過期天數-1
[String]$Now = (Get-Date).ToString("yyyyMMdd_HHmm_ss") #撮取日期時間做檔名
[String]$yymm = (Get-Date).ToString("yyyyMM") #撮取年月做Log檔名
[String]$Source = "$Drv1\BatchFile" #備份來源
[String]$ZipDestination = "$Drv1\BatchBackup" #備份目錄
[String]$ZipDestination2 = "$Drv2\BatchBackup" #備份目錄
[String]$ZipDestination3 = "$Drv3\BatchBackup" #備份目錄
[String]$ZipDestination4 = "$Drv4\BatchBackup" #備份目錄
[String]$tempDestination = "$Drv1\BatchBackup\$Now" #Batch備份暫存工作目錄
[String]$Logfile = "D:\BatchFile\Backuplog$yymm.txt" #LogFile
[String]$loginfo = "[INFO]"
[String]$logwarn = "[WARN]"
[String]$logerr = "[ERR ]"
#=====================Personal====================================================
[String]$PFTemp = "D:\BackupTemp\$Now" #個人資料備份暫存目錄
[String]$PFEDrv = "$Drv3\PFBackup" #Neo8GPFBackup
[String]$PFDesktop = "\Desktop" #個人桌面檔案
[String]$PFDocuments = "\Documents" #個人文件
[String]$PFDownload = "\Downloads" #個人下載
[String]$PFFavorites = "\Favorites" #我的最愛
[String]$PFPictures = "\Pictures" #個人圖片
[String]$FLXXX = "D:\XXX"
[String]$FLDocuments = "D:\Documents"
[Array]$PFData = $PFDesktop,$PFDocuments,$PFDownload,$PFFavorites,$PFPictures
[String]$ZipPFDestination = "$Drv4\PFBackup"
[Bool]$Checklogfile = Test-Path $Logfile
[Bool]$ChecktempExist = Test-Path $tempDestination #檢查Batch暫存目錄使否存在
[Bool]$CheckPFTempExist = Test-Path $PFTemp #檢查個人暫存目錄使否存在
[Bool]$CheckZipExist = Test-Path $ZipDestination\$Now.zip #檢查備份檔案是否存在
[Bool]$CheckFirstUSB = Test-Path $Drv1\PFBackup\ #檢查第一隨身碟是否存在
[Bool]$CheckSecondUSB = Test-Path $Drv2 #檢查第二隨身碟是否存在
[Bool]$CheckThirdUSB = Test-Path $Drv3 #檢查第三隨身碟是否存在
$OldBatchs = Get-ChildItem $ZipDestination #過期Batch檔案陣列
$OldBatchs2 = Get-ChildItem $ZipDestination2 -ErrorAction SilentlyContinue
$OldBatchs3 = Get-ChildItem $ZipDestination3 -ErrorAction SilentlyContinue
$OldBatchs4 = Get-ChildItem $ZipDestination4 -ErrorAction SilentlyContinue
$OldPFFiles = Get-ChildItem $ZipPFDestination -ErrorAction SilentlyContinue #過期個人備份檔案
#=============EventLog===========================================================
[Int]$elsrtjb = 5001 #5001 -info Start Job
[Int]$elendjb = 5002 #5002 -info End Job
[Int]$elcrtfl = 5003 #5003 -info Create file
[Int]$elcpfl = 5011 #5011 -info Copy data
[Int]$elrmfl = 5012 #5012 -info Remove data
[Int]$elinfo = 5013 #5013 -info Inforamtion
[Int]$elflex = 5014 #5014 -error File Exist
[Int]$elzpfl = 5015 #5015 -info Zip Files
[int]$elchkY = 5016 #5016 -info Check File OK
[int]$elchkN = 5017 #5017 -Error Check File Not OK
[String]$elapp = "Application"
[String]$eltyinfo = "Information"
[String]$eltywarn = "Warning"
[String]$eltyerr = "Error"
[String]$elsr = "NeoAPPs"

第一段開始先檢查Log檔在不在,不在就建立,每月一號會自動建立一個新的文字檔

1
2
3
4
IF($Checklogfile -eq $False)
{
New-Item -Path "D:\BatchBackup" -Name "Backuplog$yymm.txt" -ItemType "file"
}

備份當然要壓縮來節省空間,所以寫了下面的Function來方便後面呼叫。

1
2
3
4
5
6
7
function ZipFiles( $zipfilename, $sourcedir )
{
Add-Type -Assembly System.IO.Compression.FileSystem
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir,
$zipfilename, $compressionLevel, $false)
}

第一顆隨身碟是最主要要同步備份的,所以如我第一顆隨身碟不存在,直接終止整個備份程序。因為我也不是常常更動那些檔案,所以我有更動檔案才會做一次同步。

會先複製要備份的指定目錄到本機硬碟暫存區然後做壓縮,檔案壓縮備份完,當然要把暫存檔清掉。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
If ($Drv1 -ne "NA") #如果第一顆隨身碟存在
{
#開始備份到暫存工作目錄
Copy-Item -Path $Source -Destination $tempDestination -Recurse
#從暫存目錄壓縮至備份目的地
Compress-Archive -Path $tempDestination -DestinationPath $ZipDestination\$Now.zip
Remove-Item -Path $tempDestination -Force -Recurse
#刪除過期之檔案
foreach($oldBatch in $OldBatchs)
{
$Olderday = ((Get-Date) - $OldBatch.LastWriteTime).Days
if ($Olderday -gt $Expireday -and $OldBatch.PsISContainer -ne $True)
{
$OldBatch.Delete()
}

}
}
ELSE #如果第一顆隨身碟不存在,終止所有備份程序
{
LogWrite "$logerr First USB can not Detect, Backup treminate."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcrtfl -EntryType $eltyinfo -Message "First USB can not Detect, Backup treminate."
Exit
}

 

 

第二顆和第三顆隨身碟動作雷同,只是同步指定目錄的檔案而已。

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
If ($Drv2 -ne "NA") #如果第二顆隨身碟存在,開始同步批次檔案到指定目錄
{
Copy-Item -Path $Source -Destination $Drv2 -Recurse -Force
#同步BatchFile檔案
Copy-Item -Path $Source -Destination $Drv2\BatchFile -Recurse -Force
#從第一隨身碟複製備份檔案至第二隨身碟備份目錄
Copy-Item -Path $ZipDestination\$Now.zip -Destination $Drv2\BatchBackup
#刪除過期之檔案
foreach($oldBatch in $OldBatchs)
{
$Olderday = ((Get-Date) - $OldBatch.LastWriteTime).Days
if ($Olderday -gt $Expireday -and $OldBatch.PsISContainer -ne $True)
{
$OldBatch.Delete()
}

}
}

If ($Drv3 -ne "NA") #如果第三顆隨身碟存在,開始同步批次檔案到指定目錄
{
Copy-Item -Path $Source -Destination $Drv3 -Recurse -Force
#從第一隨身碟複製備份檔案至第三隨身碟備份目錄
Copy-Item -Path $ZipDestination\$Now.zip -Destination $Drv3\BatchBackup
}

 

 

這顆2T比較特別,同時備份我電腦裡面的文件。當然也還會壓縮。

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
If ($Drv4 -ne "NA") #如果第四顆隨身碟存在,開始同步批次檔案到指定目錄
{
Copy-Item -Path $Source -Destination $Drv4 -Recurse -Force
#從第一隨身碟複製備份檔案至第三隨身碟備份目錄
Copy-Item -Path $ZipDestination\$Now.zip -Destination $Drv4\BatchBackup
#個人檔案備份
If ($CheckPFTempExist -eq $True) #檢查暫存檔區是否存在,如果有先清除之
{
Remove-Item $PFTemp -Force -Recurse
}
Foreach ($PFItem in $PFData)
{
Copy-Item -Path $env:USERPROFILE$PFItem -Destination $PFTemp$PFItem -Recurse -ErrorAction SilentlyContinue
}
Copy-Item -Path $FLXXX -Destination $PFTemp\D_XXX-Recurse
Copy-Item -Path $FLDocuments -Destination $PFTemp\D_Documents -Recurse
Compress-Archive -Path $PFTemp\ -DestinationPath $ZipPFDestination\$Now.zip
Copy-Item -Path $ZipPFDestination\$Now.zip -Destination $Drv4\PFBackup
foreach($oldPFFile in $OldPFFiles)
{
$Olderday = ((Get-Date) - $OldBatch.LastWriteTime).Days
if ($Olderday -gt $Expireday -and $OldPFile.PsISContainer -ne $True)
{
$OldPFile.Delete()

}

}
Remove-Item $PFTemp -Force -Recurse

}

最後一段,備份檢查,把結果寫到Log裡面。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
LogWrite "$loginfo Backup Finish"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elendjb -EntryType $eltyinfo -Message "End Backup Data"
#備份檔案檢查
IF(Test-Path $ZipDestination\$Now.zip)
{
LogWrite "$loginfo $ZipDestination\$Now.zip found, Batchfile Zip and Backup Success"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elchkY -EntryType $eltyinfo -Message "$ZipDestination\$Now.zip found, Batchfile Zip and Backup Success"
}
Else
{
LogWrite "$logerr $ZipDestination\$Now.zip not found, Batchfile Zip and Backup Fail"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elchkN -EntryType $eltyerr -Message "$ZipDestination\$Now.zip not found, Batchfile Zip and Backup Fail"
}

IF(Test-Path $ZipPFDestination\$Now.zip)
{
LogWrite "$loginfo $ZipPFDestination\$Now.zip found, Profile Zip and Backup Success"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elchkY -EntryType $eltyinfo -Message "$ZipPFDestination\$Now.zip found, Profile Zip and Backup Success"
}
Else
{
LogWrite "$logerr $ZipPfDestination\$Now.zip not found, Profile Zip and Backup Fail"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elchkN -EntryType $eltyerr -Message "$ZipPfDestination\$Now.zip not found, Profile Zip and Backup Fail"
}

下面是整段程式碼

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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#===Backup Powershell File===

#個人資料備分->複製到D:\BackupTemp

[String]$Logfile = "D:\BatchFile\Backuplog$yymm.txt" #LogFile
[String]$loginfo = "[INFO]"
[String]$logwarn = "[WARN]"
[String]$logerr = "[ERR ]"
$DetectDrvs = "E:","F:","G:","H:","I:","J:","Z:"
Foreach ($DetectDrv1 in $DetectDrvs)
{
[Bool]$Chkdrv1 = Test-Path "$DetectDrv1\Neo1.txt"
IF ($Chkdrv1 -eq $True)
{
$Drv1 = $DetectDrv1
Break
}
ELSE
{
$Drv1="NA"
}
}
Foreach ($DetectDrv2 in $DetectDrvs)
{
[Bool]$Chkdrv2 = Test-Path "$DetectDrv2\Neo2.txt"
IF ($Chkdrv2 -eq $True)
{
$Drv2 = $DetectDrv2
Break
}
ELSE
{
$Drv2="NA"
}
}
Foreach ($DetectDrv3 in $DetectDrvs)
{
[Bool]$Chkdrv3 = Test-Path "$DetectDrv3\Neo3.txt"
IF ($Chkdrv3 -eq $True)
{
$Drv3 = $DetectDrv3
Break
}
ELSE
{
$Drv3="NA"
}
}
Foreach ($DetectDrv4 in $DetectDrvs)
{
[Bool]$Chkdrv4 = Test-Path "$DetectDrv4\Neo2T.txt"
IF ($Chkdrv4 -eq $True)
{
$Drv4 = $DetectDrv4
Break
}
ELSE
{
$Drv4="NA"
}
}
Function LogWrite
{
Param([string]$logstring)
Add-content $Logfile "$(Get-date -Format 'yyyy-MM-dd tthh:mm:ss') $logstring"
}
function ZipFiles( $zipfilename, $sourcedir )
{
Add-Type -Assembly System.IO.Compression.FileSystem
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir,
$zipfilename, $compressionLevel, $false)
}

#-------------------------code-by-Neo-----------------------------------
[int]$Expireday = 10 #想要之過期天數-1
[String]$Now = (Get-Date).ToString("yyyyMMdd_HHmm_ss") #撮取日期時間做檔名
[String]$yymm = (Get-Date).ToString("yyyyMM") #撮取年月做Log檔名
[String]$Source = "$Drv1\BatchFile" #備份來源
[String]$ZipDestination = "$Drv1\BatchBackup" #備份目錄
[String]$ZipDestination2 = "$Drv2\BatchBackup" #備份目錄
[String]$ZipDestination3 = "$Drv3\BatchBackup" #備份目錄
[String]$ZipDestination4 = "$Drv4\BatchBackup" #備份目錄
[String]$tempDestination = "$Drv1\BatchBackup\$Now" #Batch備份暫存工作目錄
[String]$Logfile = "D:\BatchFile\Backuplog$yymm.txt" #LogFile
[String]$loginfo = "[INFO]"
[String]$logwarn = "[WARN]"
[String]$logerr = "[ERR ]"
#=====================Personal====================================================
[String]$PFTemp = "D:\BackupTemp\$Now" #個人資料備份暫存目錄
[String]$PFEDrv = "$Drv3\PFBackup" #Neo8GPFBackup
[String]$PFDesktop = "\Desktop" #個人桌面檔案
[String]$PFDocuments = "\Documents" #個人文件
[String]$PFDownload = "\Downloads" #個人下載
[String]$PFFavorites = "\Favorites" #我的最愛
[String]$PFPictures = "\Pictures" #個人圖片
[String]$FLXXX = "D:\XXX"
[String]$FLDocuments = "D:\Documents"
[Array]$PFData = $PFDesktop,$PFDocuments,$PFDownload,$PFFavorites,$PFPictures
[String]$ZipPFDestination = "$Drv4\PFBackup"
[Bool]$Checklogfile = Test-Path $Logfile
[Bool]$ChecktempExist = Test-Path $tempDestination #檢查Batch暫存目錄使否存在
[Bool]$CheckPFTempExist = Test-Path $PFTemp #檢查個人暫存目錄使否存在
[Bool]$CheckZipExist = Test-Path $ZipDestination\$Now.zip #檢查備份檔案是否存在
[Bool]$CheckFirstUSB = Test-Path $Drv1\PFBackup\ #檢查第一隨身碟是否存在
[Bool]$CheckSecondUSB = Test-Path $Drv2 #檢查第二隨身碟是否存在
[Bool]$CheckThirdUSB = Test-Path $Drv3 #檢查第三隨身碟是否存在
$OldBatchs = Get-ChildItem $ZipDestination #過期Batch檔案陣列
$OldBatchs2 = Get-ChildItem $ZipDestination2 -ErrorAction SilentlyContinue
$OldBatchs3 = Get-ChildItem $ZipDestination3 -ErrorAction SilentlyContinue
$OldBatchs4 = Get-ChildItem $ZipDestination4 -ErrorAction SilentlyContinue
$OldPFFiles = Get-ChildItem $ZipPFDestination -ErrorAction SilentlyContinue #過期個人備份檔案
#=============EventLog===========================================================
[Int]$elsrtjb = 5001 #5001 -info Start Job
[Int]$elendjb = 5002 #5002 -info End Job
[Int]$elcrtfl = 5003 #5003 -info Create file
[Int]$elcpfl = 5011 #5011 -info Copy data
[Int]$elrmfl = 5012 #5012 -info Remove data
[Int]$elinfo = 5013 #5013 -info Inforamtion
[Int]$elflex = 5014 #5014 -error File Exist
[Int]$elzpfl = 5015 #5015 -info Zip Files
[int]$elchkY = 5016 #5016 -info Check File OK
[int]$elchkN = 5017 #5017 -Error Check File Not OK
[String]$elapp = "Application"
[String]$eltyinfo = "Information"
[String]$eltywarn = "Warning"
[String]$eltyerr = "Error"
[String]$elsr = "NeoAPPs"

IF($Checklogfile -eq $False)
{
New-Item -Path "D:\BatchBackup" -Name "Backuplog$yymm.txt" -ItemType "file"
LogWrite "$loginfo $yymm logfile Created"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcrtfl -EntryType $eltyinfo -Message "LogFile : Backuplog$yymm.txt created in D:\BatchBackup"
}

LogWrite "===================S=T=A=R=T====B=A=C=K=U=P==================="
Write-EventLog -LogName $elapp -Source $elsr -EventId $elsrtjb -EntryType $eltyinfo -Message "Start Backup Data."

If ($Drv1 -ne "NA") #如果第一顆隨身碟存在
{
LogWrite "$loginfo First USB Detect, Driver letter is $Drv1."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcrtfl -EntryType $eltyinfo -Message "First USB Detect, Driver letter is $Drv1."
#開始備份到暫存工作目錄
Copy-Item -Path $Source -Destination $tempDestination -Recurse
LogWrite "$loginfo Copy $Source to $tempDestination"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "Copy $Source to $tempDestination"
#從暫存目錄壓縮至備份目的地
Compress-Archive -Path $tempDestination -DestinationPath $ZipDestination\$Now.zip
Logwrite "$loginfo Zip file from $tempDestination to $ZipDestination\$Now.zip."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elzpfl -EntryType $eltyinfo -Message "Zip file from $tempDestination to $ZipDestination\$Now.zip."
Remove-Item -Path $tempDestination -Force -Recurse
#刪除過期之檔案
foreach($oldBatch in $OldBatchs)
{
$Olderday = ((Get-Date) - $OldBatch.LastWriteTime).Days
if ($Olderday -gt $Expireday -and $OldBatch.PsISContainer -ne $True)
{
$OldBatch.Delete()
LogWrite $loginfo "Remove old file $OldBatch."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elrmfl -EntryType $eltyinfo -Message "Remove old file $OldBatch."
}

}
}
ELSE #如果第一顆隨身碟不存在,終止所有備份程序
{
LogWrite "$logerr First USB can not Detect, Backup treminate."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcrtfl -EntryType $eltyinfo -Message "First USB can not Detect, Backup treminate."
Exit
}

If ($Drv2 -ne "NA") #如果第二顆隨身碟存在,開始同步批次檔案到指定目錄
{
LogWrite "$loginfo Second USB Detect, Driver letter is $Drv2."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcrtfl -EntryType $eltyinfo -Message "Second USB Detect, Driver letter is $Drv2."
Copy-Item -Path $Source -Destination $Drv2 -Recurse -Force
LogWrite "$loginfo $Drv2 avaible, Sync $Source Batchfile to $Drv2 Batchfile."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "$Drv2 avaible, copy Batchfile to $Drv2 Batchfile."
#同步BatchFile檔案
Copy-Item -Path $Source -Destination $Drv2\BatchFile -Recurse -Force
LogWrite "$loginfo Sync $Source to $Drv2\BatchFile."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "$loginfo Sync $Source to $Drv2\BatchFile."
#從第一隨身碟複製備份檔案至第二隨身碟備份目錄
Copy-Item -Path $ZipDestination\$Now.zip -Destination $Drv2\BatchBackup
LogWrite "$loginfo Copy $ZipDestination\$Now.zip to $Drv2\BatchBackup."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "$loginfo Copy $ZipDestination\$Now.zip to $Drv2\BatchBackup."
#刪除過期之檔案
foreach($oldBatch in $OldBatchs)
{
$Olderday = ((Get-Date) - $OldBatch.LastWriteTime).Days
if ($Olderday -gt $Expireday -and $OldBatch.PsISContainer -ne $True)
{
$OldBatch.Delete()
LogWrite $loginfo "Remove old file $OldBatch."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elrmfl -EntryType $eltyinfo -Message "Remove old file $OldBatch."
}

}
}

If ($Drv3 -ne "NA") #如果第三顆隨身碟存在,開始同步批次檔案到指定目錄
{
LogWrite "$loginfo Third USB Detect, Driver letter is $Drv3."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcrtfl -EntryType $eltyinfo -Message "Third USB Detect, Driver letter is $Drv3."
Copy-Item -Path $Source -Destination $Drv3 -Recurse -Force
LogWrite "$loginfo $Drv3 avaible, copy Batchfile to $Drv3 Batchfile."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "$Drv3 avaible, copy Batchfile to $Drv3 Batchfile."
#從第一隨身碟複製備份檔案至第三隨身碟備份目錄
Copy-Item -Path $ZipDestination\$Now.zip -Destination $Drv3\BatchBackup
LogWrite "$loginfo Copy $ZipDestination\$Now.zip to $Drv3\BatchBackup."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "$loginfo Copy $ZipDestination\$Now.zip to $Drv3\BatchBackup."
}

If ($Drv4 -ne "NA") #如果第四顆隨身碟存在,開始同步批次檔案到指定目錄
{
LogWrite "$loginfo Third USB Detect, Driver letter is $Drv4."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcrtfl -EntryType $eltyinfo -Message "USB2TB Detect, Driver letter is $Drv4."
Copy-Item -Path $Source -Destination $Drv4 -Recurse -Force
LogWrite "$loginfo $Drv4 avaible, copy Batchfile to $Drv4 Batchfile."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "$Drv4 avaible, copy Batchfile to $Drv4 Batchfile."
#從第一隨身碟複製備份檔案至第三隨身碟備份目錄
Copy-Item -Path $ZipDestination\$Now.zip -Destination $Drv4\BatchBackup
LogWrite "$loginfo Copy $ZipDestination\$Now.zip to $Drv4\BatchBackup."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "$loginfo Copy $ZipDestination\$Now.zip to $Drv4\BatchBackup."
#個人檔案備份
If ($CheckPFTempExist -eq $True) #檢查暫存檔區是否存在,如果有先清除之
{
Remove-Item $PFTemp -Force -Recurse
LogWrite "$logwarn Temp file exists. Remove them"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcrmfl -EntryType $eltywarn -Message "$logwarn Temp file exists. Remove them."
}
Foreach ($PFItem in $PFData)
{
Copy-Item -Path $env:USERPROFILE$PFItem -Destination $PFTemp$PFItem -Recurse -ErrorAction SilentlyContinue
Logwrite "$loginfo Copy $env:USERPROFILE$PFItem to $PFTemp$PFItem."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "Copy $env:USERPROFILE$PFItem to $PFTemp$PFItem."
}
Copy-Item -Path $FLXXX -Destination $PFTemp\D_XXX -Recurse
LogWrite "$loginfo Copy $FLXXX to $PFTemp\D_XXX."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "Copy $FLXXX to $PFTemp\D_XXX."

Copy-Item -Path $FLDocuments -Destination $PFTemp\D_Documents -Recurse
LogWrite "$loginfo Copy $FLDocuments to $PFTemp\D_Documents."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "$FLDocuments to $PFTemp\D_Documents."

Compress-Archive -Path $PFTemp\ -DestinationPath $ZipPFDestination\$Now.zip
Logwrite "$loginfo Compress file from $PFTemp\ to $ZipPFDestination\$Now.zip."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elzpfl -EntryType $eltyinfo -Message "Compress file from $PFTemp\ to $ZipPFDestination\$Now.zip."

Copy-Item -Path $ZipPFDestination\$Now.zip -Destination $Drv4\PFBackup
LogWrite "$loginfo Copy $ZipPFDestination\$Now.zip to $Drv4\PFBackup"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elcpfl -EntryType $eltyinfo -Message "Copy $ZipPFDestination\$Now.zip to $Drv4\PFBackup"

foreach($oldPFFile in $OldPFFiles)
{
$Olderday = ((Get-Date) - $OldBatch.LastWriteTime).Days
if ($Olderday -gt $Expireday -and $OldPFile.PsISContainer -ne $True)
{
$OldPFile.Delete()
LogWrite "$loginfo Remove old file $OldPFile."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elrmfl -EntryType $eltyinfo -Message "Remove old file $OldPFile."
}

}
Remove-Item $PFTemp -Force -Recurse
LogWrite "$loginfo Remove Temp file $PFTemp."
Write-EventLog -LogName $elapp -Source $elsr -EventId $elrmfl -EntryType $eltyinfo -Message "Remove Temp file $PFTemp."

}

LogWrite "$loginfo Backup Finish"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elendjb -EntryType $eltyinfo -Message "End Backup Data"
#備份檔案檢查
IF(Test-Path $ZipDestination\$Now.zip)
{
LogWrite "$loginfo $ZipDestination\$Now.zip found, Batchfile Zip and Backup Success"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elchkY -EntryType $eltyinfo -Message "$ZipDestination\$Now.zip found, Batchfile Zip and Backup Success"
}
Else
{
LogWrite "$logerr $ZipDestination\$Now.zip not found, Batchfile Zip and Backup Fail"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elchkN -EntryType $eltyerr -Message "$ZipDestination\$Now.zip not found, Batchfile Zip and Backup Fail"
}

IF(Test-Path $ZipPFDestination\$Now.zip)
{
LogWrite "$loginfo $ZipPFDestination\$Now.zip found, Profile Zip and Backup Success"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elchkY -EntryType $eltyinfo -Message "$ZipPFDestination\$Now.zip found, Profile Zip and Backup Success"
}
Else
{
LogWrite "$logerr $ZipPfDestination\$Now.zip not found, Profile Zip and Backup Fail"
Write-EventLog -LogName $elapp -Source $elsr -EventId $elchkN -EntryType $eltyerr -Message "$ZipPfDestination\$Now.zip not found, Profile Zip and Backup Fail"
}

 

 
Please follow and like us:

使用Powershell修改機碼-IE列印邊界

大多數一般IT都會使用批次檔或是reg檔來修改機碼,但是自從我開始學習Powershell之後,我能用Powershell做的,我盡可能都會用Powershell。畢竟我之前的整套裝機流程從Batch改成PS之後,就是一條不歸路了,畢竟用Powershell會比起用Batch來的有優越感。

今天的任務是我要在User的Profile下修改他的IE列印邊界。

目標

需要寫入的機碼

因為我需要寫入的機碼實在不少,所以我變數命名是有規則的

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
#IE Printer Setting
$RegistryPath130 = "HKCU:\SOFTWARE\Microsoft\Internet Explorer\PageSetup"
$Name130 = "font"
$Value130 = ""
$Ptype130 = "String"
$Name131 = "footer"
$Value131 = "&u&b&d"
$Ptype131 = "String"
$Name132 = "header"
$Value132 = "&w&bPage &p of &P"
$Ptype132 = "String"
$Name133 = "margin_bottom"
$Value133 = "0.393700"
$Ptype133 = "String"
$Name134 = "margin_left"
$Value134 = "0.196850"
$Ptype134 = "String"
$Name135 = "margin_right"
$Value135 = "0.196850"
$Ptype135 = "String"
$Name136 = "margin_top"
$Value136 = "0.393700"
$Ptype136 = "String"
$Name137 = "Print_Background"
$Value137 = "no"
$Ptype137 = "String"
$Name138 = "Shrink_To_Fit"
$Value138 = "yes"
$Ptype138 = "String"

$breaktime = 500

IF(!(Test-Path $RegistryPath130))
{
New-Item -Path $RegistryPath130 -Force | Out-Null
}
New-ItemProperty -Path $RegistryPath130 -Name $Name130 -Value $Value130 -PropertyType $Ptype130 -Force
Start-Sleep -m $breaktime
New-ItemProperty -Path $RegistryPath131 -Name $Name131 -Value $Value131 -PropertyType $Ptype131 -Force
Start-Sleep -m $breaktime
New-ItemProperty -Path $RegistryPath132 -Name $Name132 -Value $Value132 -PropertyType $Ptype132 -Force
Start-Sleep -m $breaktime
New-ItemProperty -Path $RegistryPath133 -Name $Name133 -Value $Value133 -PropertyType $Ptype133 -Force
Start-Sleep -m $breaktime
New-ItemProperty -Path $RegistryPath134 -Name $Name134 -Value $Value134 -PropertyType $Ptype134 -Force
Start-Sleep -m $breaktime
New-ItemProperty -Path $RegistryPath135 -Name $Name135 -Value $Value135 -PropertyType $Ptype135 -Force
Start-Sleep -m $breaktime
New-ItemProperty -Path $RegistryPath136 -Name $Name136 -Value $Value136 -PropertyType $Ptype136 -Force
Start-Sleep -m $breaktime
New-ItemProperty -Path $RegistryPath137 -Name $Name137 -Value $Value137 -PropertyType $Ptype137 -Force
Start-Sleep -m $breaktime
New-ItemProperty -Path $RegistryPath138 -Name $Name138 -Value $Value138 -PropertyType $Ptype138 -Force
Start-Sleep -m $breaktime

因為我測試發現機碼寫入太快,不知道為什麼有時候會寫不完整,所以我每次寫一個值就會暫停500毫秒,避免沒有寫完整。

Please follow and like us:

外掛CodeColorer上線

未來也許會分享一些Powershell的東西

裝個外掛CodeColorer來試試看

1
2
3
Write-host "Hello World!"

Write-host "Please Standby.

感覺好像不錯!

Please follow and like us: