How to change tab width when converting to JSON in Powershell

Because the PowerShell’s ConvertTo-Json produces non-deterministic indentation, the current answers will not produce JSON that has exactly two spaces for each depth in the data structure. To get each level of nested data indented exactly two spaces more than the enclosing level requires rebuilding the indentation. (For what it’s worth, looks like this was fixed … Read more

PowerShell string default parameter value does not work as expected

Okay, found the answer @ https://www.codykonior.com/2013/10/17/checking-for-null-in-powershell/ Assuming: Param( [string] $stringParam = $null ) And the parameter was not specified (is using default value): # will NOT work if ($null -eq $stringParam) { } # WILL work: if ($stringParam -eq “” -and $stringParam -eq [String]::Empty) { } Alternatively, you can specify a special null type: Param( … Read more

rename-item and override if filename exists

As noted by @lytledw, Move-Item -Force works great for renaming and overwriting files. To replace the index. part of the name, you can use the -replace regex operator: Get-ChildItem index.*.txt |ForEach-Object { $NewName = $_.Name -replace “^(index\.)(.*)”,’$2′ $Destination = Join-Path -Path $_.Directory.FullName -ChildPath $NewName Move-Item -Path $_.FullName -Destination $Destination -Force }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)