PowerShell讀取JSON配置文件

使用Get-ContentConvertFrom-Json讀取JSON配置文件,以下是示例代碼:

// settings.json
{
  "RUN_DATE": null,
  "xl": {
    "xlWBATWorksheet": -4167,
    "xlUp": -4162,
    "xlCellTypeVisible": 12,
    "xlPasteValuesAndNumberFormats": 12,
    "XlFileFormat": {
      "xlExcel8": 56
    },
    "XlCutCopyMode": {
      "xlCopy": 1,
      "xlCut": 2
    },
    "xlCalculationAutomatic": -4105,
    "xlCalculationManual": -4135
  }
}
$CONF = (Get-Content "settings.json") | ConvertFrom-Json
$xl = $CONF.xl
$RUN_DATE = $CONF.RUN_DATE
If($RUN_DATE -eq $null) {
    $RUN_DATE = (Get-Date)
} Else {
    $RUN_DATE = [datetime]::ParseExact($RUN_DATE, 'yyyyMMdd', $null)
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章