以下脚本有什么作用?

时间:2018-05-27 22:51:44

标签: windows powershell powershell-v2.0 powershell-v3.0

@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:Drive中,想知道这个脚本做了什么。

这是脚本的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 :(得分:3)

Powershell部分:

  1. 获取您的驱动器映射
  2. 检查哪些空间已用完(可能全部用完)
  3. 循环浏览并删除Windows10Upgrade文件夹中扩展名为.esd
  4. 的所有文件

    e.g。

    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 } 
    

    了解其工作原理。

相关问题