Matt Penny

Subscribe to Matt Penny feed Matt Penny
Updated: 14 hours 41 min ago

Moving to https://mattypenny.github.io/

Sun, 2020-01-05 08:10

Much as I like WordPress, I’m moving all of this stuff over to:

https://mattypenny.github.io/

Categories: DBA Blogs

Pester script parameter passing not working

Wed, 2019-05-08 04:22
Problem

I was trying to parameterize a Pester script. The script looked like this:


param (
[string]$ComputerName,
[string]$IPAddress
)

write-dbg "$ComputerName: "
write-dbg "
$IPAddress: "

Describe "$ComputerName is visible" {

It "It is ping-able" {
    {test-connection $ComputerName -count 1} | Should Not Throw

    $(test-connection $ComputerName -count 1 | Measure-Object).count | Should Be 1
}

}

…but passing the parameters wasn’t working.

Solution

The problem was that I was calling the script as follows
$ Invoke-Pester @{PAth = c:\pester\diagnostics\simple\StandardDomainContoller.tests.ps1; Parameters=@{ComputerName = "server1.here.co.uk";IPAddress = "17.6.5.1""}}

…and the Path variable needs quotes:

$ Invoke-Pester @{PAth = 'c:\pester\diagnostics\simple\StandardDomainContoller.tests.ps1'; Parameters=@{ComputerName = "server1.here.co.uk";IPAddress = "17.6.5.1""}}

Categories: DBA Blogs

how to copy chrome bookmarks from one computer to another

Fri, 2019-03-22 12:20

copy "C:\Users\matty\AppData\Local\Google\Chrome\User Data\Default\Bookmarks"
"\sh00001\c$\Users\matty\AppData\Local\Google\Chrome\User Data\Default" -verbose

Categories: DBA Blogs

Install a vim plugin on windows

Sat, 2017-12-02 10:47

The plugin was downloaaded and un-zipped to this folder:
cd C:\Users\matty\Documents\tabular-master\tabular-master

Go to the vimfiles folder:

cd 'C:\Program Files (x86)\Vim\vimfiles'

Copy the files

copy C:\Users\matty\Documents\tabular-master\tabular-master* . -Recurse -Force

You need the -force (Luke) because some of the folders already exist
The new files, in this instance, are as follows:

C:\Program Files (x86)\Vim\vimfiles\after
C:\Program Files (x86)\Vim\vimfiles\autoload
C:\Program Files (x86)\Vim\vimfiles\doc
C:\Program Files (x86)\Vim\vimfiles\plugin
C:\Program Files (x86)\Vim\vimfiles.gitignore
C:\Program Files (x86)\Vim\vimfiles.netrwhist
C:\Program Files (x86)\Vim\vimfiles\LICENSE.md
C:\Program Files (x86)\Vim\vimfiles\README.md
C:\Program Files (x86)\Vim\vimfiles\after\plugin
C:\Program Files (x86)\Vim\vimfiles\after\plugin\TabularMaps.vim
C:\Program Files (x86)\Vim\vimfiles\autoload\tabular.vim
C:\Program Files (x86)\Vim\vimfiles\doc\Tabular.txt
C:\Program Files (x86)\Vim\vimfiles\plugin\Tabular.vim

Categories: DBA Blogs

Get day of week number in command

Tue, 2017-11-14 05:23

This is a slight tweak to code at: http://www.techsupportforum.com/forums/f128/solved-windows-7-batch-getting-day-of-week-moved-from-vista-7-a-565632.html

FOR /F "skip=1" %%A IN ('WMIC Path Win32_LocalTime Get DayOfWeek' ) DO (
if %%A GEQ 1 set DOW=%%A
)
echo %DOW%

Categories: DBA Blogs

sketchnote of Gael Colas on ‘Devops’

Fri, 2017-07-14 10:56


Categories: DBA Blogs

Importing windows scheduled tasks into a Powershell object before 5.0

Mon, 2016-07-18 07:43

You don’t need this on Powershell 5.0 and upwards because there’s a built-in cmdlet, but for previous versions:


convertfrom-csv $(schtasks /Query /S server1 /TN "run somesstuff" /V /FO CSV)

HostName : server1
TaskName : \run somesstuff
Next Run Time : N/A
Status : Ready
Logon Mode : Interactive only
Last Run Time : 13/07/2016 10:05:43
Last Result : 0
Author : matt
Task To Run : C:\powershell\Modules\somesstuff-PCs\run-somesstuff.bat
Start In : N/A
Comment : Scheduled job which does some stuff
Scheduled Task State :
Idle Time :
Power Management :
Run As User :
Delete Task If Not Rescheduled :
Stop Task If Runs X Hours and X Mins :
Schedule :
Schedule Type :
Start Time :
Start Date :
End Date :
Days :
Months :
Repeat: Every :
Repeat: Until: Time :
Repeat: Until: Duration :
Repeat: Stop If Still Running :

HostName : More detail at http://ourwebsite
TaskName : Enabled
Next Run Time : Disabled
Status : Stop On Battery Mode, No Start On Batteries
Logon Mode : matt
Last Run Time : Enabled
Last Result : 72:00:00
Author : Scheduling data is not available in this format.
Task To Run : One Time Only
Start In : 10:20:21
Comment : 25/05/2016
Scheduled Task State : N/A
Idle Time : N/A
Power Management : N/A
Run As User : Disabled
Delete Task If Not Rescheduled : Disabled
Stop Task If Runs X Hours and X Mins : Disabled
Schedule : Disabled
Schedule Type :
Start Time :
Start Date :
End Date :
Days :
Months :
Repeat: Every :
Repeat: Until: Time :
Repeat: Until: Duration :
Repeat: Stop If Still Running :


This is outputting from schtasks in csv format, then importing that into a PowerShell object.


Categories: DBA Blogs

sketchnote of confluence keyboard shortcuts

Mon, 2016-07-18 03:03

Confluence keyboard shortcuts sketchnote


Categories: DBA Blogs

Pester: Cannot bind argument to parameter ‘Actual’ because it is an empty string.

Tue, 2016-06-21 03:23

I’m just getting started with Pester and I got this error

   Cannot bind argument to parameter 'Actual' because it is an empty string.
   at line: 18 in C:\Program Files\WindowsPowerShell\Modules\pester\3.3.5\Functions\Assertions\Be.ps1

The code I’m testing is very simple – it just separates a ‘Property Name’ and a ‘Property Value’.

So, when it’s working it does this:

get-HugoNameAndValue -FrontMatterLine "Weighting: 103"
DEBUG: 09:15:37.6806 Start: get-HugoNameAndValue
DEBUG: - FrontMatterLine=Weighting: 103
DEBUG: - get-HugoNameAndValue.ps1: line 5
DEBUG: $PositionOfFirstColon: 9
DEBUG: $PropertyName : {Weighting}
DEBUG: $PropertyValue : { 103}
DEBUG: $PropertyValue : {103}

PropertyName PropertyValue
------------ -------------
Weighting    103          

When I ran it from Pester I got this

GetHugoNameAndValue 06/21/2016 08:45:19 $ invoke-pester
Describing get-HugoNameAndValue
DEBUG: 08:45:56.3377 Start: get-HugoNameAndValue
DEBUG: - FrontMatterLine=Weighting: 103
DEBUG: - get-HugoNameAndValue.ps1: line 5
DEBUG: $PositionOfFirstColon: 9
DEBUG: $PropertyName : {Weighting}
DEBUG: $PropertyValue : { 103}
DEBUG: $PropertyValue : {103}
 [-] returns name and value 189ms
   Cannot bind argument to parameter 'Actual' because it is an empty string.
   at line: 18 in C:\Program Files\WindowsPowerShell\Modules\pester\3.3.5\Functions\Assertions\Be.ps1
Tests completed in 189ms
Passed: 0 Failed: 1 Skipped: 0 Pending: 0

My Pester code was:

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"

Describe "get-HugoNameAndValue" {
    It "returns name and value" {
        $Hugo = get-HugoNameAndValue -FrontMatterLine "Weighting: 103"
        $value = $Hugo.Value
        $value | Should Be '103'
    }
}

The problem here was simply that I’d got the name of the Property wrong. It was ‘PropertyName’ not just ‘Name’

So I changed the Pester

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"

Describe "get-HugoNameAndValue" {
    It "returns name and value" {
        $Hugo = get-HugoNameAndValue -FrontMatterLine "Weighting: 103"
        $value = $Hugo.PropertyValue
        $value | Should Be '103'
    }
}

….and then it worked

invoke-pester
Describing get-HugoNameAndValue
DEBUG: 09:22:21.2291 Start: get-HugoNameAndValue
DEBUG: - FrontMatterLine=Weighting: 103
DEBUG: - get-HugoNameAndValue.ps1: line 5
DEBUG: $PositionOfFirstColon: 9
DEBUG: $PropertyName : {Weighting}
DEBUG: $PropertyValue : { 103}
DEBUG: $PropertyValue : {103}
 [+] returns name and value 99ms
Tests completed in 99ms
Passed: 1 Failed: 0 Skipped: 0 Pending: 0

Categories: DBA Blogs

sketchnote of Ed Wilson’s talk on ‘Operations Management Suite’

Fri, 2016-05-27 11:17

Wilson, Ed - Microsoft Operations Management Suite

The OMS blog is: https://blogs.technet.microsoft.com/msoms/
The Scripting Guy blog is: https://blogs.technet.microsoft.com/heyscriptingguy/
Ed Wilson is on twitter here: https://twitter.com/ScriptingGuys
The London Powershell Users Group tweets here: https://twitter.com/lonpsug
The UK Powershell Users Group is http://www.get-psuguk.org/

Keywords: OMS, Powershell


Categories: DBA Blogs

Pages