How to specify application pool identity user and password from PowerShell

You would do this as follows: Import-Module WebAdministration Set-ItemProperty IIS:\AppPools\app-pool-name -name processModel -value @{userName=”user_name”;password=”password”;identitytype=3} See this document here for an explanation, and a reference of the indentity type numeric for the user type you will run the app pool under: http://www.iis.net/configreference/system.applicationhost/applicationpools/add/processmodel

How to get Powershell Invoke-Restmethod to return body of http 500 code response

The other answer does get you the response, but you need an additional step to get the actual body of the response, not just the headers. Here is a snippet: try { $result = Invoke-WebRequest … } catch { $result = $_.Exception.Response.GetResponseStream() $reader = New-Object System.IO.StreamReader($result) $reader.BaseStream.Position = 0 $reader.DiscardBufferedData() $responseBody = $reader.ReadToEnd(); }

How do I update JSON file using PowerShell

Here is a way : $a = Get-Content ‘D:\temp\mytest.json’ -raw | ConvertFrom-Json $a.update | % {if($_.name -eq ‘test1’){$_.version=3.0}} $a | ConvertTo-Json -depth 32| set-content ‘D:\temp\mytestBis.json’ According to @FLGMwt and @mikemaccana I improve the ConvertTo-Json with -depth 32 because the default depth value is 2 and for object deeper than 2 you will receive class informations … Read more

Copy-item Files in Folders and subfolders in the same directory structure of source server using PowerShell

This can be done just using Copy-Item. No need to use Get-Childitem. I think you are just overthinking it. Copy-Item -Path C:\MyFolder -Destination \\Server\MyFolder -recurse -Force I just tested it and it worked for me. edit: included suggestion from the comments # Add wildcard to source folder to ensure consistent behavior Copy-Item -Path $sourceFolder\* -Destination … Read more

How to load a JSON file and convert it to an object of a specific type?

Try casting the custom object to FooObject: $foo = [FooObject](Get-Content ‘C:\path\to\your.json’ | Out-String | ConvertFrom-Json) If that doesn’t work, try constructing the FooObject instance with the properties of the input object (provided the class has a constructor like that): $json = Get-Content ‘C:\path\to\your.json’ | Out-String | ConvertFrom-Json $foo = New-Object FooObject ($json.Foo, $json.Bar, $json.Baz) If … Read more

Difference between PSObject, Hashtable, and PSCustomObject

One scenario where [PSCustomObject] is used instead of HashTable is when you need a collection of them. The following is to illustrate the difference in how they are handled: $Hash = 1..10 | %{ @{Name=”Object $_” ; Index=$_ ; Squared = $_*$_} } $Custom = 1..10 | %{[PSCustomObject] @{Name=”Object $_” ; Index=$_ ; Squared = … Read more

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