param( [Parameter(Mandatory=$false,Position=0)][switch]$child ) function Get-PSVersion { if (Test-Path Variable:PSVersionTable) { return $PSVersionTable.PSVersion.ToString() } else { return "1.0.0.0" } } function Test-AdminRights { $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) return $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) } function Set-DFSActive { foreach ($line in $(Get-Content -Path $Global:cfg)) { $dfsLink = $line.Split(':')[0] $smbPath = $line.Split(':')[1] Set-Location "Microsoft.PowerShell.Core\FileSystem::$dfsLink" Start-Process dfsutil.exe -ArgumentList "client","property","state","active","$dfsLink","$smbPath" } } $Global:cfg = $MyInvocation.MyCommand.Path.Replace('.ps1', '.cfg') if (!(Test-AdminRights)) { if (!($child)) { $params = New-Object System.Collections.ArrayList foreach ($key in $MyInvocation.BoundParameters.Keys) { [void]$params.Add("-$key") [void]$params.Add($PSBoundParameters.$key) } Start-Process powershell.exe -Verb RunAs -ArgumentList ( "-NoProfile -File ""{0}"" -child $($params -join " ")" -f $($MyInvocation.MyCommand.Definition) ) exit } } else { if (!(Test-Path -Path "$env:SystemRoot\System32\dfsutil.exe")) { try { $system = $(Get-WmiObject -Class "Win32_OperatingSystem") # Windows 11, 10, 2022, 2019, 2016, 8.1, 2012R2 if (($system.Version -like '10.0.*') -or ($system.Version -like '6.3.*')) { # Workstation if ($system.ProductType -like '1') { $capability = "Rsat.FileServices.Tools" if (!(Get-WindowsCapability -Name "*$capability*" -Online | Where-Object State -eq 'Installed' -ErrorAction Stop)) { Get-WindowsCapability -Name "*$capability*" -Online | Add-WindowsCapability -Online -ErrorAction Stop } } # DomainController, Server if (($system.ProductType -like '2') -or ($system.ProductType -like '3')) { $capability = "RSAT-DFS-Mgmt-Con" if(!(Get-WindowsFeature -Name "*$capability*" | Where-Object InstallState -eq 'Installed' -ErrorAction Stop)) { Get-WindowsFeature -Name "*$capability*" | Install-WindowsFeature -IncludeAllSubFeature -ErrorAction Stop } } } # Windows 7, 2008R2 if ($system.Version -like '6.1.*') { # Workstation if ($system.ProductType -like '1') { if (!(Get-WmiObject -Class "Win32_QuickFixEngineering" | Where-Object { $_.HotFixID -like '*958830' })) { if ($system.OSArchitecture -like '32*') { Start-Process wusa.exe -ArgumentList "\\capital.local\sys\repo\distrib\microsoft\rsat\win7\Windows6.1-KB958830-x86.msu","/quiet","/norestart" -ErrorAction Stop -Wait } if ($system.OSArchitecture -like '64*') { Start-Process wusa.exe -ArgumentList "\\capital.local\sys\repo\distrib\microsoft\rsat\win7\Windows6.1-KB958830-x64.msu","/quiet","/norestart" -ErrorAction Stop -Wait } } Start-Process dism.exe -ArgumentList "/Online","/Enable-Feature:RemoteServerAdministrationTools" -ErrorAction Stop -Wait Start-Process dism.exe -ArgumentList "/Online","/Enable-Feature:RemoteServerAdministrationTools-Roles" -ErrorAction Stop -Wait Start-Process dism.exe -ArgumentList "/Online","/Enable-Feature:RemoteServerAdministrationTools-Roles-FileServices" -ErrorAction Stop -Wait Start-Process dism.exe -ArgumentList "/Online","/Enable-Feature:RemoteServerAdministrationTools-Roles-FileServices-Dfs" -ErrorAction Stop -Wait } # DomainController, Server if (($system.ProductType -like '2') -or ($system.ProductType -like '3')) { } } } catch [System.Management.Automation.CommandNotFoundException] { Write-Host "Powershell $(Get-PSVersion) need to update" Start-Sleep 10 Exit 1 } } if (!(Test-Path -Path "$($Global:cfg)")) { Exit 1 } Set-DFSActive Exit 0 }