Что делает следующий скрипт? - PullRequest
0 голосов
/ 28 мая 2018
@echo off
setlocal
set _RunOnceValue=%~d0%\Windows10Upgrade\Windows10UpgraderApp.exe /SkipSelfUpdate
set _RunOnceKey=Windows10UpgraderApp.exe
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /V "%_RunOnceKey%" /t REG_SZ /F /D "%_RunOnceValue%"
PowerShell -Command "&{ Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Used -gt 0 } | ForEach-Object { $esdOriginalFilePath = 'C:\Windows10Upgrade\\*.esd'; $driveName = $_.Name; $esdFilePath = $esdOriginalFilePath -replace '^\w',$driveName; if (Test-Path $esdFilePath) { Remove-Item $esdFilePath } } }"

Нашел этот пакетный скрипт, спрятанный где-то на моем диске C: и хочу знать, что делает этот скрипт.

Это часть скрипта Powershell:

Get-PSDrive -PSProvider FileSystem |
  Where-Object { $_.Used -gt 0 } |
    ForEach-Object { 
        $esdOriginalFilePath = 'C:\Windows10Upgrade\\*.esd'; 
        $driveName = $_.Name; 
        $esdFilePath = $esdOriginalFilePath -replace '^\w',$driveName; 
        if (Test-Path $esdFilePath) 
            { Remove-Item $esdFilePath } 
    }

1 Ответ

0 голосов
/ 28 мая 2018

Часть Powershell:

  1. Получает сопоставления дисков
  2. Проверяет, занимают ли они в них место (вероятно, все)
  3. Проходит через них иудаляет все файлы в папках Windows10Upgrade с расширением .esd

например

M:\Windows10Upgrade\*.esd
S:\Windows10Upgrade\*.esd
T:\Windows10Upgrade\*.esd

См. ниже закомментированную версию кода, поясняющую каждую строку:

# Get shared drives
Get-PSDrive -PSProvider FileSystem |
  # Filter just those with used space
  Where-Object { $_.Used -gt 0 } |
    # Go through each of those drives
    ForEach-Object { 
      # Set a variable with the Windows10Upgrade folder and *.esd wildcard
      $esdOriginalFilePath = 'C:\Windows10Upgrade\\*.esd'; 
      # Get the drive name for the one currently in the loop ($_)
      $driveName = $_.Name; 
      # Use a regex replace of the first 'word' character with drivename (e.g. C -> E, C -> W)
      $esdFilePath = $esdOriginalFilePath -replace '^\w',$driveName; 
      # Check if the path exists
      if (Test-Path $esdFilePath) 
          # If so, remove the file
          { Remove-Item $esdFilePath } 
    }

Я бы предложил запустить это в Powershell:

Get-PSDrive -PSProvider FileSystem |
  Where-Object { $_.Used -gt 0 } 

Чтобы получить представление о том, как это работает.

...