<commit_before>---
layout: post
title: PowerShell Octopus Deploy Snippets
author: Andy
categories: code
tags:
- PowerShell
- Octopus Deploy
---

Some useful snippets to execute in the Octopus Deploy script console.

``` powershell
# List files in a directory

Get-ChildItem -Path "C:\Temp\SomeDirectory" -File
```

``` powershell
# Display contents of a file

Get-Content "D:\Applications\Server\Application\Version\web.config"
```

``` powershell
# Update contents of web.config AppSetting

$webConfig = "D:\Applications\Server\Application\Version\web.config"
$doc = (Get-Content $webConfig) -as [Xml]
$obj = $doc.configuration.appSettings.add | where {$_.Key -eq 'SomeAppSettingKey'}
Write-Output $obj
#$obj.value = 'SomeNewValue'
#$doc.Save($webConfig)
```<commit_msg>Edit post<commit_after>---
layout: post
title: PowerShell Octopus Deploy Snippets
author: Andy
categories: code
tags:
- PowerShell
- Octopus Deploy
---

Some useful snippets to execute in the Octopus Deploy script console.

``` powershell
# List files in a directory

Get-ChildItem -Path "C:\Temp\SomeDirectory" -File
```

``` powershell
# Display contents of a file

Get-Content "D:\Applications\Server\Application\Version\web.config"
```

``` powershell
# Update contents of web.config AppSetting

$webConfig = "D:\Applications\Server\Application\Version\web.config"
$doc = (Get-Content $webConfig) -as [Xml]
$obj = $doc.configuration.appSettings.add | where {$_.Key -eq 'SomeAppSettingKey'}
Write-Output $obj
#$obj.value = 'SomeNewValue'
#$doc.Save($webConfig)
```

``` powershell
# Show all the IIS bindings on a machine

Import-Module Webadministration
Get-ChildItem -Path IIS:\Sites
```
{'fraction_non_alphanumeric': 0.13349368610944076, 'fraction_numerical': 0.0, 'mean_word_length': 4.838596491228071, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3825994', 'n_tokens_mistral': 547, 'n_tokens_neox': 514, 'n_words': 153}