class Inspec::Resources::WindowsFileSystemResource

Public Instance Methods

info(partition) click to toggle source
# File lib/inspec/resources/filesystem.rb, line 114
    def info(partition)
      cmd = inspec.command <<-EOF.gsub(/^\s*/, "")
        $disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='#{partition}'"
        $disk.Size = $disk.Size / 1KB
        $disk.FreeSpace = $disk.FreeSpace / 1KB
        $disk | select -property DeviceID,Size,FileSystem,FreeSpace | ConvertTo-Json
      EOF

      raise Inspec::Exceptions::ResourceSkipped, "Unable to get available space for partition #{partition}" if cmd.stdout == "" || cmd.exit_status.to_i != 0

      begin
        fs = JSON.parse(cmd.stdout)
      rescue JSON::ParserError => e
        raise Inspec::Exceptions::ResourceFailed,
              "Failed to parse JSON from Powershell. " \
              "Error: #{e}"
      end
      {
        name: fs["DeviceID"],
        size_kb: fs["Size"].to_i,
        free_kb: fs["FreeSpace"].to_i,
        type: fs["FileSystem"],
      }
    end