Write-Host vs Write-Information in PowerShell 5

The Write-* cmdlets allow you to channel the output of your PowerShell code in a structured way, so you can easily distinguish messages of different severity from each other. Write-Host: display messages to an interactive user on the console. Unlike the other Write-* cmdlets this one is neither suitable nor intended for automation/redirection purposes. Not … Read more

PowerShell 5.1 – How to uninstall module which is currently use

The problem could be that your existing PowerShell session is “locking” the module by loading possible elements from it (such as global variables or constants) even though you are trying to unload it (Remove-Module). The cleanest way to be sure it isn’t locked is to exit the PowerShell session. If you need to keep the … Read more

Set-Content appends a newline (line break, CRLF) at the end of my file

tl;dr (PSv5+; see bottom for older versions): (Get-Content webtemp.config) -replace ‘database=myDb;’, ‘database=newDb;’ -join “`n” | Set-Content -NoNewline -Force web1.config Note: Replace “`n” with “`r`n” if you want Windows-style CRLF line endings rather than Unix-style LF-only line endings (PowerShell and many utilities can handle both). In PSv5+, Set-Content supports the -NoNewline switch, which instructs Set-Content not … Read more

Iterating through a JSON file PowerShell

PowerShell 3.0+ In PowerShell 3.0 and higher (see: Determine installed PowerShell version) you can use the ConvertFrom-Json cmdlet to convert a JSON string into a PowerShell data structure. That’s convenient and unfortunate at the same time – convenient, because it’s very easy to consume JSON, unfortunate because ConvertFrom-Json gives you PSCustomObjects, and they are hard … Read more

List file names in a folder matching a pattern, excluding file content

Select-String is doing what you told it to. Emphasis mine. The Select-String cmdlet searches for text and text patterns in input strings and files. So if you are just looking to match with file names just use -Filter of Get-ChildItem or post process with Where-Object Get-ChildItem -Path $path -Recurse -Filter “*sample*” That should return all … Read more

Making a PowerShell POST request if a body param starts with ‘@’

You should be able to do the following: $params = @{“@type”=”login”; “username”=”xxx@gmail.com”; “password”=”yyy”; } Invoke-WebRequest -Uri http://foobar.com/endpoint -Method POST -Body $params This will send the post as the body. However – if you want to post this as a Json you might want to be explicit. To post this as a JSON you can specify … Read more

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