Matt Penny
Moving to https://mattypenny.github.io/
Much as I like WordPress, I’m moving all of this stuff over to:
Pester script parameter passing not working
I was trying to parameterize a Pester script. The script looked like this:
param (
[string]$ComputerName,
[string]$IPAddress
)
write-dbg "$ComputerName: "
$IPAddress: "
write-dbg "
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.
SolutionThe 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""}}
how to copy chrome bookmarks from one computer to another
copy "C:\Users\matty\AppData\Local\Google\Chrome\User Data\Default\Bookmarks"
"\sh00001\c$\Users\matty\AppData\Local\Google\Chrome\User Data\Default" -verbose
Install a vim plugin on windows
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
Get day of week number in command
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%
sketchnote of Javier Villegas on ‘Sqlserver 2017 – community-driven enhancements’
sketchnote of Chris Presley, Richard Weiss and Warner Chaves on ‘Running sqlserver on Linux’
Importing windows scheduled tasks into a Powershell object before 5.0
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.
Pester: Cannot bind argument to parameter ‘Actual’ because it is an empty string.
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
sketchnote of Ed Wilson’s talk on ‘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
Sketchnote of Ben Hillis, Dustin Kirkland, Russ Alexander, Scott Hanselman discussion about ‘Linux Command Line on Windows’
sketchnote of Jes Borland’s talk ‘Minimize Data Loss with Advanced Restore Methods’
SQLPass page for the webcast is: VC Data Architecture SQL Server Users Group: PASS Data Architecture Virtual Chapter > Meeting Detail
Jes blogs here: Less Than Dot – Blog – Jes Borland
The slides and SQL for this presentation are at: Less Than Dot – Blog – MinimizeDataLossWithAdvancedRestoreMethods