Powershell & SVN – Export files to CSV

Function Get-SvnLogData() { ([xml](svn log -v --xml 'http://svn/trunk')).log.logentry | % { $nestedEntry = $_ $_.paths.path | % { $path = $_ $nestedEntry | Select-Object -Property ` Author, ` @{n='Revision'; e={([int]$_.Revision)}}, ` @{n='Date'; e={Get-Date $_.Date }}, ` @{n='Action'; e={$path.action }}, ` @{n='Path'; e={$path.InnerText }}` } } } Get-SvnLogData | where { $_.Date -ge (Get-Date '16-04-2013') } | Select-Object Revision,Date,Path,Author | sort -property ` @{ Expression="Path"; Descending=$false }, ` @{ Expression="Revision"; Descending=$true } | Export-CSV c:\test.csv

April 2013 · Smart Tech

NServiceBus Powershell Install

NServiceBus PowerShell Install $Arguments = '/install /startManually /serviceName:{0} /displayName:{0} NServiceBus.Production /username:{1} /password:{2}' -f 'McKelt.securitytokenservice.nservicebus.messagehandler', 'xxxx@au.McKelt.net', 'PasswordGoesHere' $nServiceBus = Resolve-Path -Path nServiceBus.Host.exe; Write-Host -Object ('Argument string is: {0}' -f $Arguments); Write-Host -Object ('Path to nServiceBus.Host.exe is: {0}' -f $nServiceBus); Start-Process -Wait -NoNewWindow -FilePath $nServiceBus -ArgumentList $Arguments -RedirectStandardOutput tmp.txt;

March 2013 · Smart Tech

Powershell script to delete mail from specific folder

function Remove-MailItem { [CmdletBinding(SupportsShouldProcess=$true)] param ( [parameter(Mandatory=$true)] [string]$mailfolder, [string]$parentfolder ) $ol = new-object -comobject "Outlook.Application"; # Map to the MAPI namespace $mapi = $ol.getnamespace("mapi"); $targetfolder = '' if ($parentfolder.Length -eq 0) { $targetfolder = $mapi.Folders.Item(1).Folders.Item("Inbox").Folders.Item($mailfolder) } else { $targetfolder = $mapi.Folders.Item(1).Folders.Item("Inbox").Folders.Item($parentfolder).Folders.Item($mailfolder) } foreach ($item in $targetfolder.Items) { try { $item.Delete() } catch [Exception]{ Write-Host "Failed to delete item: " + $item.Subject Write-Host $_.Exception.ToString() } } function Clear-DeletedMail { $outlook = New-Object -ComObject Outlook.Application foreach ($folder in $outlook.Session.Folders){ foreach($mailfolder in $folder.Folders ) { if ($mailfolder.Name -eq "Deleted Items" -and $mailfolder.Items.Count -gt 0){ foreach ($item in $mailfolder.Items){$item.Delete()} } } } } } Remove-MailItem -mailfolder "Cafe" Remove-MailItem -mailfolder "COLSupport" Remove-MailItem -mailfolder "Failed Logins" -parentfolder "COLSupport" Remove-MailItem -mailfolder "IISReset" -parentfolder "COLSupport" Remove-MailItem -mailfolder "Not Urgent" -parentfolder "COLSupport" Remove-MailItem -mailfolder "Production" -parentfolder "COLSupport"

October 2012 · Smart Tech

Round house and powershell

Using https://github.com/chucknorris/roundhouse for powershell to get automated database change management Task UpgradeDatabase{ if (($environment -eq 'integration') -or ($environment -eq 'uat')) { # round house variables $rh = "C:\\dev\\Phoenix\\trunk\\Tools\\RoundhousE\\console\\rh.exe" $connectionString = "Data Source=localhost;Database=XXX; User Id=XXXuser; Password=XXX;Connect Timeout=100;" $indexesFolder = "C:\\dev\\Phoenix\\trunk\\Database\\10-Indexes" $schemaChangesFolder = "C:\\dev\\Phoenix\\trunk\\Database\\11-SchemaChanges" ## build server? if (Test-Path "D:\\Code\\") { $rh = "D:\\Code\\Phoenix\\trunk\\Tools\\RoundhousE\\console\\rh.exe" $indexesFolder = "D:\\Code\\Phoenix\\trunk\\Database\\10-Indexes" $schemaChangesFolder = "D:\\Code\\Phoenix\\trunk\\Database\\11-SchemaChanges" if ($environment -eq 'integration') { $connectionString = "Data Source=xxxxx;Database=rrrr\_Integration; User Id=rrrr; Password=rrrr;" } else { $connectionString = "Data Source=xxxx;Database=rrrrr\_UAT; User Id=rrrrr; Password=rrrrr;" } } Write\-Host "Database upgrade started" $s1 = " -c " $s2 = " $connectionString " $s3 = " -ix " $s4 = "$indexesFolder" $s5 = " -u " $s6 = "$schemaChangesFolder" $args = $s1 + " ""$s2" "" + $s3 + " ""$s4" "" + $s5 + " ""$s6""" + " -ni -ct 300" Write\-Host $args Start-Process -FilePath $rh -ArgumentList $args -PassThru Write\-Host "Database upgrade complete" } } The following tables are created ...

June 2012 · Smart Tech

Converting ints to char

Convert.ToChar(34).ToString() Converting the corresponding number to an character 33 = ! 34 = " 35 = # 36 = $ 37 = % 38 = & 39 = ’ 40 = ( 41 = ) 42 = * 43 = + 44 = , 45 = - 46 = . 47 = / 48 = 0 49 = 1 50 = 2 51 = 3 52 = 4 53 = 5 54 = 6 55 = 7 56 = 8 57 = 9 58 = : 59 = ; 60 = < 61 = = 62 = > 63 = ? 64 = @ 65 = A 66 = B 67 = C 68 = D 69 = E 70 = F 71 = G 72 = H 73 = I 74 = J 75 = K 76 = L 77 = M 78 = N 79 = O 80 = P 81 = Q 82 = R 83 = S 84 = T 85 = U 86 = V 87 = W 88 = X 89 = Y 90 = Z 91 = [ 92 = \ 93 = ] 94 = ^ 95 = _ 96 = ` 97 = a 98 = b 99 = c 100 = d 101 = e 102 = f 103 = g 104 = h 105 = i 106 = j 107 = k 108 = l 109 = m 110 = n 111 = o 112 = p 113 = q 114 = r 115 = s 116 = t 117 = u 118 = v 119 = w 120 = x 121 = y 122 = z 123 = { 124 = | 125 = } 126 = ~

June 2008 · Smart Tech