小编Kir*_*ran的帖子

如何将今天的日期作为 powershell 中参数的默认值

我想创建一个脚本来帮助复制在某个时间范围内修改的文件。我想将该$EndDate参数保留为可选,在这种情况下,我希望脚本使用今天的日期作为默认值。

下面是脚本:

param (
  [Parameter(Mandatory=$True)]
  [string]$Path,

  [Parameter(Mandatory=$True)]
  [string]$targetDir,

  [Parameter(Mandatory=$True)]
  [string]$BeginDate,

  [Parameter(Mandatory=$False)]
  [string]$EndDate,

  [switch]$force
)

 Get-ChildItem -Path $Path -Recurse | Where-Object {$_.LastWriteTime -gt $BeginDate -and $_.LastWriteTime -lt $EndDate }| cp -Destination $targetDir -Force
Run Code Online (Sandbox Code Playgroud)

parameters powershell

5
推荐指数
1
解决办法
3201
查看次数

如何在 Azure 中使用 Terraform 创建多个安全规则?

我正在尝试创建一个包含多个安全规则的网络安全组。这个想法是创建一个列表变量(端口范围)并在 .tf 文件中插入列表项。下面的脚本抛出一个错误“priority.

"Error: azurerm_network_security_group.k8hway: security_rule.0: invalid or unknown key: count"
Run Code Online (Sandbox Code Playgroud)

下面是 Terraform 代码:

resource "azurerm_network_security_group" "NSG" {
  name     = "NSG-Demo"
  location = "${azurerm_resource_group.main.location}"
  resource_group_name  = "${azurerm_resource_group.main.name}"

  security_rule  {
      count = "${length(var.inbound_port_ranges)}"
      name                       = "sg-rule-${count.index}"
      direction                  = "Inbound"
      access                     = "Allow"
      priority                   = "(100 * (${count.index} + 1))"
      source_address_prefix      = "*"
      source_port_range          = "*"
      destination_address_prefix = "*"
      destination_port_range     = "${element(var.inbound_port_ranges, count.index)}"
      protocol                   = "TCP"
    }
}
Run Code Online (Sandbox Code Playgroud)

azure terraform terraform-provider-azure

1
推荐指数
1
解决办法
1万
查看次数