【问题标题】:Initialize variable amount of disks with a single DSC configuration使用单个 DSC 配置初始化可变数量的磁盘
【发布时间】:2017-02-09 15:46:21
【问题描述】:

是否可以使用单个 DSC 配置将所有附加磁盘初始化到多个 VM?例如,如果 VM1 连接了 1 个磁盘,则 DSC 配置将把该磁盘初始化为磁盘 F,VM2 有 2 个磁盘,因此相同的 DSC 配置会攻击 F 和 G 的磁盘。想法是将该配置文件重用于具有以下功能的多个 VM可变数量的磁盘而不会出错。

【问题讨论】:

  • 你是在目标节点上编译配置吗?
  • 是的,我正在为此使用 Azure DSC 扩展。

标签: powershell dsc


【解决方案1】:

如果您在本地编译,这应该可以工作。由于该语言允许强制构建声明的状态。您可以查询磁盘并设置状态。

我的示例中驱动器号的分配相当粗略。你也应该改进它。

这里使用xStorage which can be found on the PowerShell Gallery

Configuration disks
{
  $DriveLetters = 'DEFGHIJKLMNOPQSRT'
  Import-DscResource -ModuleName xStorage

  Node localhost
  {
    Get-Disk | Where-Object {$_.NumberOfPartitions -lt 1} | Foreach-Object {
      Write-Verbose "disk($($_.Number))" -Verbose
      xDisk "disk($($_.Number))"
      {
        DriveLetter = $DriveLetters[$_.Number]
        DiskNumber = $_.Number
        FSFormat = 'NTFS'        
      }
    }
  }
}

【讨论】:

  • 失败并出现不同的错误:The DSC Extension received an incorrect input: Compilation errors occurred while processing configuration 'disks'. Please review the errors reported in error stream and modify your configuration code appropriately. Index operation failed; the array index evaluated to null. Exception calling "InvokeWithContext" with "2" argument(s): "Index operation failed; the array index evaluated to null." Index operation failed; the array index evaluated to null.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-15
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 1970-01-01
  • 2021-08-20
相关资源
最近更新 更多