Skip to content

Instantly share code, notes, and snippets.

View grenade's full-sized avatar

rob thijssen grenade

View GitHub Profile
$connectionString = "Data Source=localhost;Initial Catalog=SomeDatabase;Integrated Security=True"
$config = "path\to\app.config"
$xml = (Get-Content $config) -as [xml]
$xml.SelectSingleNode('/configuration/connectionStrings/add[@name="ConnectionString.Key"]/@connectionString').set_InnerXML($connectionString)
$xml.Save($config)
@grenade
grenade / ServiceDeploy.ps1
Last active January 7, 2025 21:18
Install a Windows service on a remote computer. Set the credentials for the service to run under, grant SeServiceLogonRight to the account and set service recovery options.
<#
.Synopsis
Installs a Windows service on a remote computer.
Sets the credentials for the service to run under.
Grants SeServiceLogonRight to the account.
Sets service recovery options.
.Parameter computerName
Defines the name of the computer which will host the service.
Default is the local computer on which the script is run.
.Parameter name
@grenade
grenade / github-last-release.ps1
Last active January 4, 2016 02:49
Create a GitHub release and upload an asset. If the release (identified by $release_tag_name) or asset (identified by $asset_name) exist, they will be replaced.
<#
.Synopsis
Get the last release.
.Example
.\github-last-release.ps1 -username GITHUB_USERNAME -token OAUTH_TOKEN -repo GITHUB_REPOSITORY -release_tag_name v1.0.0 -asset_name "C:\temp\MyRelease.zip" -asset_label "Zip archive"
#>
param (
[string] $api_base = "https://api.github.com",
[Parameter (Mandatory = $true)]
@grenade
grenade / robocopy.ps1
Last active January 24, 2025 09:23
Wrap robocopy in powershell to get standard (0/1) exit codes.
<#
.Synopsis
Robocopy wrapper with standard 0 (success) and 1 (failure) exit codes.
.Parameter source
Defines the source folder
.Parameter target
Defines the target folder
.Parameter include
Defines the files to include. Accepts wildcards. Eg: -include *.dll,*.pdb
Optional, Default value is $null and will include all files from source.
@grenade
grenade / skip-verification.ps1
Last active August 29, 2015 13:56
Warning: This script is incomplete. Its not a good implementation since the correct token usage is commented out and instead all assemblies are registered. Register an assembly for strong name verification skipping using the public key .snk file.
param(
[string] $snk
)
$noSDK = $true
foreach ($folder in @("Program Files", "Program Files (x86)")){
$sns = (Get-ChildItem -Path ("{0}\{1}\Microsoft SDKs\Windows" -f $env:SystemDrive, $folder) -Filter "sn.exe" -Recurse | Select-Object FullName)
foreach ($sn in $sns){
#$token = (& $sn.FullName -tp $snk | Select-String "^Public key token is " | % {$_.Line.Split(" ")[4]})
#& $sn.FullName -Vr *,$token
& $sn.FullName -Vr *
param(
[string] $assemblyInfoFile,
[hashtable] $parameters
)
Write-Host ("`$assemblyInfoFile: {0}" -f $assemblyInfoFile)
foreach($key in $($parameters.Keys)){
if($parameters[$key] -ne $null){
$assemblyInfo = Get-Content $assemblyInfoFile
$pattern = ('^\[assembly: {0}\("(.*)"\)\]' -f $key)
$oldValue = ($assemblyInfo | Select-String -Pattern $pattern | % { $_.Matches } ).Groups[1].Value
param(
[string] $archive,
[string] $binding = "*:80:"
)
$xml = [xml] (Get-Content $archive)
if ($xml.SelectSingleNode("//bindings/binding") -and !$xml.SelectSingleNode("//bindings/binding[@bindingInformation='$binding']")) {
$xml.SelectSingleNode("//bindings").AppendChild($xml.SelectSingleNode("//bindings/binding").Clone())
$xml.SelectSingleNode("//bindings/binding/@bindingInformation").set_InnerXML($binding)
$xml.Save($archive)
}
@grenade
grenade / poke.ps1
Created February 18, 2014 15:39
Poke an xml file and change it's values.
param (
[hashtable] $pokes,
[string] $config
)
$xml = (Get-Content $config) -as [xml]
foreach($xpath in $($pokes.Keys)){
$xml.SelectSingleNode($xpath).set_InnerXML($pokes[$xpath])
}
$xml.Save($config)
@grenade
grenade / restore-teamcity.cmd
Last active May 5, 2016 03:32
Restore TeamCity from a backup file, preserving artifacts and plugins
:: set these variables to match TeamCity environment
SET TEAMCITY_DATA_PATH=D:\Config\TeamCity
SET TEAMCITY_DATA_BACKUP=D:\Temp\TeamCity
SET TEAMCITY_HOME=C:\TeamCity
SET TEAMCITY_BACKUP_FILE=TeamCity_Backup_xxx_xxx.zip
:: maintainDB expects these directories to be empty or absent.
move /Y %%TEAMCITY_DATA_PATH%%\config %%TEAMCITY_DATA_BACKUP%%\config
move /Y %%TEAMCITY_DATA_PATH%%\system %%TEAMCITY_DATA_BACKUP%%\system
@grenade
grenade / remove-nuget-package.sql
Created February 21, 2014 11:57
Remove all versions of a package from a private nuget gallery server. The IIS app pool must be recycled after running the SQL transaction, in order for the changes to show up correctly in the gallery.
DECLARE @PackageRegistrationKey int
SELECT @PackageRegistrationKey = [Key]
FROM PackageRegistrations
WHERE Id = 'MyNastyPackage'
BEGIN TRANSACTION
DELETE pf
FROM [NuGetGallery].[dbo].[PackageFrameworks] pf
JOIN Packages p ON pf.Package_Key = p.[Key]
WHERE PackageRegistrationKey = @PackageRegistrationKey