Skip to content

Commit dcb33ea

Browse files
authored
Optimize script
Delete "replace" actions by "get-content -match".
1 parent f05883a commit dcb33ea

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

Office-365/Check-Office2016Activation renamed to Office-365/Check-Office2016Activation.ps1

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
$launchdate = Get-Date -f "yyyy.MM.dd-HHhmmmss"
2+
$Office2016FolderPath = 'C:\Program Files\Microsoft Office\Office16'
23
$CookieFile = 'C:\Users\' + $env:username + '\AppData\Local\Microsoft\Office\16.0\office365ForBusiness.txt'
4+
$Office365LicenceStatusResult = 'C:\' + $env:HOMEPATH + '\office365forbusinessactstat.txt'
35

46

57
function Check-Office365ForBusinessActivation () {
6-
C:\Windows\System32\cscript.exe 'C:\Program Files\Microsoft Office\Office16\OSPP.VBS' /dstatus | Out-File $env:temp\office365forbusinessactstat.txt
7-
$ActivationStatus = $($Things = $(Get-Content $env:temp\office365forbusinessactstat.txt -raw) `
8-
-replace ":"," =" `
9-
-split "---------------------------------------" `
10-
-notmatch "---Processing--------------------------" `
11-
-notmatch "---Exiting-----------------------------"
12-
$Things | ForEach-Object {
13-
$Props = ConvertFrom-StringData -StringData ($_ -replace '\n-\s+')
14-
New-Object psobject -Property $Props | Select-Object "SKU ID", "LICENSE NAME", "LICENSE DESCRIPTION", "LICENSE STATUS"
15-
})
16-
8+
C:\Windows\System32\cscript.exe 'C:\Program Files\Microsoft Office\Office16\OSPP.VBS' /dstatus | Out-File -Force $Office365LicenceStatusResult
9+
$ActivationStatus = $(get-content $Office365LicenceStatusResult -ReadCount 24 | foreach { $_ -match "LICENSE STATUS" })
10+
1711
$Var = "Office Activated "
18-
for ($i=0; $i -le $ActivationStatus.Count-2; $i++) {
19-
if ($ActivationStatus[$i]."LICENSE STATUS" -eq "---LICENSED---") {
12+
if ($ActivationStatus -match "LICENSE STATUS: ---LICENSED--- ") {
2013
$Var = $Var + "OK "
2114
}
2215

2316
else {
2417
$Var = $Var + "Bad "
2518
}
26-
}
2719

2820
if ($Var -like "*Bad*") {
2921
echo "Office Not Activated"

0 commit comments

Comments
 (0)