-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix-netvsc.ps1
46 lines (39 loc) · 2.93 KB
/
fix-netvsc.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
<#
.SYNOPSIS
Restores correctly signed netvsc.sys from windows driver store after Citrix PVS Target Device setup on WS2016
.Description
After running a Windows Component Cleanup (via DISM, OSDBuilder, ...) this driver has no longer a valid signature.
This seems to be a problem with Windows itself and occures since netvsc.sys file version 10.0.14393.351 from KB3197954 released on 16/10/27
.EXAMPLE
.INPUTS
.OUTPUTS
.NOTES
Script generates a log file when called and exits always with 0.
Can be perfectly used in MDT/SCCM task sequence.
Script was made for german OS versions. Users and Groups may need to be renamed accordingly (i.e. Administratoren = Administrators, Benutzer = Users)
.LINK
#>
Write-Verbose "Setting Arguments" -Verbose
$StartDTM = (Get-Date)
$Vendor = "My Company"
$Product = "netvsc.sys fix"
$Version = "1.0"
$LogPS = "${env:SystemRoot}" + "\Temp\$Vendor $Product $Version PS Wrapper.log"
Start-Transcript $LogPS
Write-Verbose "Taking ownership and setting permissions of netvsc.sys ..." -Verbose
(Start-Process "$env:systemroot\System32\takeown.exe" -ArgumentList "/F $env:systemroot\system32\drivers\netvsc.sys /A" -Passthru -Wait).ExitCode
(Start-Process "$env:systemroot\System32\cacls.exe" -ArgumentList "$env:systemroot\system32\drivers\netvsc.sys /e /G Administratoren:F" -Passthru -Wait).ExitCode
# Copy File to System32
Write-Verbose "Copy signed file from DriverStore" -Verbose
Get-ChildItem -Path $env:systemroot\System32\DriverStore\FileRepository\wnetvsc.inf_amd* -Recurse | Where {$_.Name -eq "netvsc.sys"} | Sort LastWriteTime -Descending | Select -First 1 | Copy-Item -Destination "$env:systemroot\system32\drivers" -Force
Write-Verbose "Reset ownership of netvsc.sys" -Verbose
(Start-Process "$env:systemroot\System32\cacls.exe" -ArgumentList "$env:systemroot\system32\drivers\netvsc.sys /e /r SYSTEM" -Passthru -Wait).ExitCode
(Start-Process "$env:systemroot\System32\cacls.exe" -ArgumentList "$env:systemroot\system32\drivers\netvsc.sys /e /g SYSTEM:F" -Passthru -Wait).ExitCode
(Start-Process "$env:systemroot\System32\cacls.exe" -ArgumentList "$env:systemroot\system32\drivers\netvsc.sys /e /r Administratoren" -Passthru -Wait).ExitCode
(Start-Process "$env:systemroot\System32\cacls.exe" -ArgumentList "$env:systemroot\system32\drivers\netvsc.sys /e /r Benutzer" -Passthru -Wait).ExitCode
(Start-Process "$env:systemroot\System32\cacls.exe" -ArgumentList "$env:systemroot\system32\drivers\netvsc.sys /e /g Benutzer:R" -Passthru -Wait).ExitCode
(Start-Process "$env:systemroot\System32\cacls.exe" -ArgumentList "$env:systemroot\system32\drivers\netvsc.sys /e /g ""NT SERVICE\TrustedInstaller"":F" -Passthru -Wait).ExitCode
(Start-Process "$env:systemroot\System32\icacls.exe" -ArgumentList "$env:systemroot\system32\drivers\netvsc.sys /setowner ""NT SERVICE\TrustedInstaller""" -Passthru -Wait).ExitCode
Stop-Transcript
# End script, returning always 0 (SUCCESS)
Exit 0