Hi,
I have below code in powershell script
$ignore = @('.txt','.log','.dat','.ps1' ,'.bat','.zip')
Get-ChildItem -Path c:\temp -File | foreach {
""
$.Name
if ($ignore -contains $.Extension ) {
# Leave it alone
} else {
$newname = $_.name + ".dat"
"rename to $newname"
}
}
I am trying to put $ignore variable in to Json file and import it into power shell script like this:
config.json
{
"ignoreExtensions":[".txt",".log",".xls"]
, "sourcePath":"reports\export"
}
powershell script. example.ps1
Tried multiple ways:
Try 1: (didn't work)
$configFile = 'C:\files\config.json'
$configJSON = Get-Content $configFile | Out-String | ConvertFrom-Json
$ignore = @($configJSON.ignoreExtensions)
Try 2: Didn't work
$configFile = 'C:\files\config.json'
$configJSON = Get-Content $configFile
$ignore = @($configJSON.ignoreExtensions)
None of this is working. I need to get those array of values and loop through all files in directory and check if file has extension. I am missing something in getting json array to powershell script array.