anchor.diff:  @rem limitations under the License.
   @rem
   
  -@setlocal
  +@rem Use delayed environment expansion so that ERRORLEVEL can be evaluated with the
  +@rem !ERRORLEVEL! syntax which evaluates at execution of the line of script, not when
  +@rem the line is read. See help for the /E switch from cmd.exe /? .
  +@setlocal ENABLEDELAYEDEXPANSION
   
   <%= "SETX HTTP_PROXY \"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] %>
  -mkdir <%= bootstrap_directory %>
  +
  +@set BOOTSTRAP_DIRECTORY=<%= bootstrap_directory %>
  +@echo Checking for existing directory "%BOOTSTRAP_DIRECTORY%"...
  +@if NOT EXIST %BOOTSTRAP_DIRECTORY% (
  +    @echo Existing directory not found, creating.
  +    @mkdir %BOOTSTRAP_DIRECTORY%
  +) else (
  +    @echo Existing directory found, skipping creation.
  +)
   
   > <%= bootstrap_directory %>\wget.vbs (
    <%= win_wget %>
  
positive.code: :install
  @rem Install Chef using chef-client MSI installer
  
  @set "REMOTE_SOURCE_MSI_URL=https://www.opscode.com/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%"
  @set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
  @set "FALLBACK_QUERY_STRING=&DownloadContext=PowerShell"
  
  cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
  
  @rem Work around issues found in Windows Server 2012 around job objects not respecting WSMAN memory quotas
  @rem that cause the MSI download process to exceed the quota even when it is increased by administrators.
  @rem Retry the download using a more memory-efficient mechanism that only works if PowerShell is available.
  @if ERRORLEVEL 1 (      
      echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
      echo Warning: Retrying download with PowerShell if available
      if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
      @powershell -ExecutionPolicy Unrestricted -NoProfile -NonInteractive "& '<%= bootstrap_directory %>\wget.ps1' '%REMOTE_SOURCE_MSI_URL%%FALLBACK_QUERY_STRING%' '%LOCAL_DESTINATION_MSI_PATH%'"
  
      if NOT ERRORLEVEL 1 (
          echo Download succeeded
      ) else (
          echo Failed to download "%REMOTE_SOURCE_MSI_URL%"
          echo Subsequent attempt to install the downloaded MSI is likely to fail
      )
  )
  
  <%= install_chef %>
  
  @endlocal
  
  > <%= bootstrap_directory %>\validation.pem (
   <%= validation_key %>
  )
  
  <% if @config[:encrypted_data_bag_secret] -%>
  > <%= bootstrap_directory %>\encrypted_data_bag_secret (
  
negative.code: echo server.start >>C:\chef_zero_startup.rb
  C:\opscode\chef\embedded\bin\ruby C:\chef_zero_startup.rb
  
  @echo Starting chef to bootstrap the node...
  <%= start_chef %>
  
  