powershell
#TodayILearned that for #Powershell’s Get-ADUser, using -identity will return an error:
$ $ErrorActionPreference = 'Stop'
$ try {Get-AdUser -identity phineas.fogg} catch {"In catch"}
In catch
….whereas using -filter won’t
$ try {Get-AdUser -filter {samaccountname -eq 'phineas.fogg'}} catch {"In catch"}
$
My slightly late-in-the-day New Year’s Resolution is to use #Powershell’s Out-GridView more often and Format-Table less often

Function to return markdown link for a URL
This function accepts a URL and returns a markdown link for the URL:
function Get-MarkdownLinkForUrl {
<#
.SYNOPSIS
Get the webpage, extract the title, and build a markdown link for the specified URL
#>
[CmdletBinding()]
[OutputType([String])]
param (
[Parameter(Mandatory=$True)][string]$Url
)
$DebugPreference = $PSCmdlet.GetVariableValue('DebugPreference')
$Webpage = invoke-webrequest $Url
$Webpage.Content -match "<title>(?<title>.*)</title>" | out-null
$Title = $matches['Title']
"[$Title]($Url)"
}
set-alias gmd Get-MarkdownLinkForUrl
It’s run as follows:
Get-MarkdownLinkForUrl https://www.theguardian.com/football/2012/may/19/bayern-munich-chelsea-champions-league-final
…which returns:
[Chelsea win Champions League on penalties over Bayern Munich | Champions League 2011-12 | The Guardian](https://www.theguardian.com/football/2012/may/19/bayern-munich-chelsea-champions-league-final)
which when rendered looks like this:
I can only ever remember git add, commit, diff, rm and push...and I couldn't be bothered to rtfm (Confessions of a powershell numpty, #1)
I don’t use git much, and I’m far too lazy to consult the docco so to find a command I’d probably used before I did this:
hhh git | where-object line -notmatch 'diff|add|push|commit| rm '
….where hhh is an alias to a crappy little function I wrote:
function get-MTPSavePAthHistory {
<#
.SYNOPSIS
Search through history
#>
[CmdletBinding()]
Param ($Pattern = "*",
$Tail = 50)
[string]$HistoryFile = $(Get-PSReadLineOption).HistorySavePAth
if ($Pattern -eq "*") {
get-content -tail $Tail
}
else {
Select-string "$Pattern" $HistoryFile | select-object line
}
}
Set-Alias -Name hhh -Value get-MTPSavePAthHistory
What I really did
It gets worse
Because I am a numpty, and I couldn’t remember whether whether -notmatch would work in this context, what I really did was this:
hhh git | ? line -notlike "*add*" | ? line -notlike "*diff*" | ? line -notlike "*commit*"| ? line -notlike "*push*"
I did a one page ‘‘What is Powershell?’ slide
I’m happy enough with it, but the penguin is probably too prominent. I was making the point that it’s comparable to Bash etc. I’m overfond of drawing the penguin tbh

I don’t use the ‘Close Others’ option enough in VS Code….and I end up with a couple of dozen tabs

#TodayILearned that to remove the two different timestamps I tend to use you can do this in Powershell
# Strip YYMMDDHHMISS
$ErrorText = $ErrorText -replace "_\d{12}", ""
# Strip YYYYMMDDTHHMISSnnnn
$ErrorText = $ErrorText -replace "_\d{8}T\d{10}", ""
[IO.Directory]::EnumerateFiles vs. Get-ChildItem
On my laptop, with a fairly random set of files, I found that
[http://IO.Directory]::EnumerateFiles
….is a lot quicker than
get-childitem
….given that all I wanted was the filename.
Here is the test I did:
11:24 [1.83] C:\powershell >measure-command {$x = [IO.Directory]::EnumerateFiles("c:\temp", "*", 'AllDirectories')} | select milliseconds
Milliseconds
------------
4
14:26 [0.02] C:\powershell >measure-command {$x = [IO.Directory]::EnumerateFiles("c:\temp", "*", 'AllDirectories')} | select milliseconds
Milliseconds
------------
2
14:26 [0.01] C:\powershell >measure-command {$x = [IO.Directory]::EnumerateFiles("c:\temp", "*", 'AllDirectories')} | select milliseconds
Milliseconds
------------
2
14:26 [0.01] C:\powershell >measure-command {$x = get-childitem -recurse "c:\temp"} | select milliseconds
Milliseconds
------------
137
14:26 [1.14] C:\powershell >measure-command {$x = get-childitem -recurse "c:\temp"} | select milliseconds
Milliseconds
------------
731
14:26 [0.74] C:\powershell >measure-command {$x = get-childitem -recurse "c:\temp"} | select milliseconds
Milliseconds
------------
628
Pester script parameter passing not working
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 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""}}
What I learned about powershell in 2017, according to my twitter archive
Nov 24, 2017
#TodayILearned that:
$Content = get-content somefile.txt | out-string
…preserves the line breaks in the text file
via social.technet.microsoft.com/Forums/sc…
Nov 21, 2017
set backupdir=C:\temp\vim set directory=C:\temp\vim
via @hellojs_org at blog.hellojs.org/configure…
Nov 8, 2017
#TodayILearned that the batch command equivalent of the bash sleep is Timeout
May 24, 2017
#TodayILearned that you can replace a pattern in Powershell: “images\Leopold_I_of_Belgium 226x300” -replace “[0-9][0-9]x[0-9][0-9]”,""
Mar 31, 2017
#TodayILearned that if you put a ValidateSet on a #Powershell cmdlet parameter, then ISE Tab-completion will pick it up. Very handy!
Mar 21, 2017
#TodayILearned you can omit the Get- from Powershell commands…‘tho just because you can…doesnt mean you should!
community.idera.com/powershel…
Jan 20, 2017
#TodayILearned that you can set a CSV in a here-string and turn it into an object.
Handy for small test datasets in @PSPester
Jan 3, 2017
#TodayILearned that ‘show-command’ in Powershell creates a nice little GUI window for a function or cmdlet community.idera.com/powershel…
What I learned about powershell in 2016, according to my twitter archive
Sep 27, 2016
#TodayILearned you have to:
export-modulemember -alias * -function *
to define aliases in a Powershell module
maxtblog.com/2010/07/powershell-modules-how-to-create-aliases-for-my-functions/
Sep 23, 2016
#TodayILearned that in vim to scroll down but keep the cursor in the same place, you can do Ctrl-e
Sep 15, 2016
#TodayILearned that Powershell’s get-unique cmdlet is case sensitive.
Aug 22, 2016
#TodayILearned that Powershell’s get-help -parameter option takes a parameter of the parameter. Obvious, really :)
Aug 11, 2016
#TodayILearned this vim
:vimgrep /^functio/ %
:copen
then move to the left
Aug 10, 2016
#TodayILearned that PowerShell’s get-help has a really, really useful -window option (via @maxtrinidad , shortly b4 losing my internet :( )
Jul 5, 2016
#TodayILearned that if you’re Pester-testing a bit of a #Powershell module, and you want to Mock something you need -Module option
I think.
Jun 15, 2016
#TodayILearned this is v handy if you RunAs different users $Host.UI.RawUI.WindowTitle = $env:username
Mar 7, 2016
#TodayILearned that Powershell ISE snippets live in
C:\Users\matt\Documents\WindowsPowerShell\Snippets
..if your name happens to be matt
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
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
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
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
extracting post details from wordpress xml dump with powershell
Get the xml into a variable
[xml]$xmla = get-content D:\repair_websites\salisburywiltshireandstonehenge.wordpress.2015-10-03.xml
Extract the details
select-xml -xml $xmla -xpath "//channel/item" | select -expandproperty node | ? post_type -ne "attachment" | select title
gives the following:
title
-----
Road names beginning with 'N'
Road names beginning with 'O'
Road names beginning with 'P'
Road names beginning with 'Q'
Road names beginning with 'R'
Road names beginning with 'S'
Road names beginning with 'T'
Road names beginning with 'U'
Road names beginning with 'V'
Road names beginning with 'W'
The properties of the expanded node are:
For example:
select-xml -xml $xmla -xpath "//channel/item" | select -expandproperty node | ? post_type -ne "attachment" | ? title -like "*Ramone*"
outputs:
title : 3rd June 1977 - the Ramones visit Stonehenge. Johnny stays on the bus
link : /on-this-day/june/3rd-june-1977-the-ramones-visit-stonehenge-johnny-stays-on-the-bus
pubDate : Tue, 04 Nov 2014 12:33:09 +0000
creator : creator
guid : guid
description :
encoded : {content:encoded, excerpt:encoded}
post_id : 9267
post_date : 2014-11-04 12:33:09
post_date_gmt : 2014-11-04 12:33:09
comment_status : open
ping_status : closed
post_name : 3rd-june-1977-the-ramones-visit-stonehenge-johnny-stays-on-the-bus
status : publish
post_parent : 6624
menu_order : 3
post_type : page
post_password :
is_sticky : 0
postmeta : {wp:postmeta, wp:postmeta, wp:postmeta, wp:postmeta}
To get the actual content of the post:
select-xml -xml $xmla -xpath "//channel/item" | select -expandproperty node | ? post_type -ne "attachment" | ? title -like "*Ramone*" | select -ExpandProperty encoded | fl
…gives:
#cdata-section : <a href="/images/Joey-Ramone-visited-Stonehenge.jpg"><img src="/images/Joey-Ramone-visited-Stonehenge.jpg" alt="Joey Ramone - 'visited'
Stonehenge" width="320" height="455" class="alignright size-full wp-image-9702" /></a>On either the 3rdIn 'On the Road with
the Ramones', Monte A. Melnick says that the visit occurred
<blockquote>'On the '77 tour we had a day off and noticed Stonehenge was on the way'[URL <a href="http://books.google.co.uk/books?
id=N7m8AwAAQBAJ&lpg=RA1-PR24&dq=ramones%20stonehenge&pg=RA1-PR25#v=onepage&q=ramones%20stonehenge&f=false">'On the Road with the
Ramones', by By Monte A. Melnick, Frank Meyer</a>].</blockquote>
This would have been when the Ramones were travelling back from Penzance to Canterbury - the free day being June 3rd [<a href="http://en.wikipedia.org/wiki/List_of_Ramones_concerts#1977">Wikipedia List Of Ramones Concerts</a>] or possibly the
4th June 1977, the Ramones visited Stonehenge.
Pic: By en:User:Dawkeye [<a href="http://www.gnu.org/copyleft/fdl.html">GFDL</a>, <a href="http://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA-3.0</a> or <a href="http://creativecommons.org/licenses/by-sa/2.5">CC-BY-SA-2.5</a>], <a href="http://commons.wikimedia.org/wiki/File%3AJoeyramone.jpg">via Wikimedia Commons</a>
More:
<a href="http://books.google.co.uk/books?id=c7lgKVmD0yMC&lpg=PA170&dq=ramones%20stonehenge&pg=PA171#v=onepage&q=ramones%20stonehen
ge&f=false" title="http://books.google.co.uk/books?id=c7lgKVmD0yMC&lpg=PA170&dq=ramones%20stonehenge&pg=PA171#v=onepage&q=ramones%
20stonehenge&f=false">I Slept with Joey Ramone: A Family Memoir By Mickey Leigh</a>
<a href="http://books.google.co.uk/books?id=N7m8AwAAQBAJ&lpg=RA1-PR24&dq=ramones%20stonehenge&pg=RA1-PR25#v=onepage&q=ramones%20st
onehenge&f=false" title="http://books.google.co.uk/books?id=N7m8AwAAQBAJ&lpg=RA1-PR24&dq=ramones%20stonehenge&pg=RA1-PR25#v=onepag
e&q=ramones%20stonehenge&f=false">On the Road with the Ramones By Monte A. Melnick, Frank Meyer</a>
<a href="http://books.google.co.uk/books?ei=AxPJU5u3Jae60QXB1ICQBQ&id=QTjaAAAAMAAJ&dq=ramones+stonehenge&focus=searchwithinvolume&
q=+stonehenge" title="http://books.google.co.uk/books?ei=AxPJU5u3Jae60QXB1ICQBQ&id=QTjaAAAAMAAJ&dq=ramones+stonehenge&focus=search
withinvolume&q=+stonehenge">A Time to Rock: A Social History of Rock and Roll by David P. Szatmary</a>
#cdata-section :
powershell equivalent of linux 'ps -aux | sort -k3n'
I’m not entirely sure how I managed to not find out about Win32_PerfFormattedData_PerfProc_Process before now. I think the ‘sort -k3n’ does a sort by CPU-usage, but I’m sure there’s a better way of doing it than that.
gwmi Win32_PerfFormattedData_PerfProc_Process -ComputerName $ComputerName |
Sort-Object -Property PercentProcessorTime -desc |
select idprocess, name, IODataBytesPersec, PercentPrivilegedTime,PercentProcessorTime, PercentUserTime, workingset |
Select-Object -first 11 |
ft -AutoSize
gives:
idprocess name IODataBytesPersec PercentPrivilegedTime PercentProcessorTime PercentUserTime workingset
--------- ---- ----------------- --------------------- -------------------- --------------- ----------
0 _Total 849620 100 100 18 5667786752
0 Idle 0 100 100 0 4096
5552 sqlservr 236135 0 18 18 3040718848
3680 TmListen 344690 6 6 0 10211328
10012 PccNTMon 7574 6 6 0 4706304
496 services 0 0 0 0 11198464
744 svchost#3 0 0 0 0 69857280
568 svchost#2 0 0 0 0 14368768
792 svchost#1 0 0 0 0 24203264
2132 svchost 0 0 0 0 5054464
5888 Ssms#1 0 0 0 0 190734336
powershell equivalent of linux 'ps -aux | sort -k3n'
I’m not entirely sure how I managed to not find out about Win32_PerfFormattedData_PerfProc_Process before now. I think the ‘sort -k3n’ does a sort by CPU-usage, but I’m sure there’s a better way of doing it than that.
gwmi Win32_PerfFormattedData_PerfProc_Process -ComputerName $ComputerName |
Sort-Object -Property PercentProcessorTime -desc |
select idprocess, name, IODataBytesPersec, PercentPrivilegedTime,PercentProcessorTime, PercentUserTime, workingset |
Select-Object -first 11 |
ft -AutoSize
gives:
idprocess name IODataBytesPersec PercentPrivilegedTime PercentProcessorTime PercentUserTime workingset
--------- ---- ----------------- --------------------- -------------------- --------------- ----------
0 _Total 849620 100 100 18 5667786752
0 Idle 0 100 100 0 4096
5552 sqlservr 236135 0 18 18 3040718848
3680 TmListen 344690 6 6 0 10211328
10012 PccNTMon 7574 6 6 0 4706304
496 services 0 0 0 0 11198464
744 svchost#3 0 0 0 0 69857280
568 svchost#2 0 0 0 0 14368768
792 svchost#1 0 0 0 0 24203264
2132 svchost 0 0 0 0 5054464
5888 Ssms#1 0 0 0 0 190734336
powershell error: 'Cannot perform operation because operation 'ReportWrongProviderType' is invalid'
I got the following error from a Powershell script I wrote to run SQLExress backups on a remote server.
The script runs on a Standard Edition server as a SQL Agent job. It creates and then runs a T-sql script on the remote server to backup all the databases to a folder on the remote server.
The error occurred when I migrated the job from a Windows 2003 server running SQL 2008 R2 to a Windows 2012 Server running SQL 2012
Message
A job step received an error at line 18 in a PowerShell script.
The corresponding line is "invoke-sqlcmd -outputsqlerrors $True -ServerInstance $ServerInstance -QueryTimeout 3600 -InputFile d:\dbawork\admin\bin\sp_BackupDatabases.sql > $SqlOutputLog".
Correct the script and reschedule the job.
The error information returned by PowerShell is: "Cannot perform operation because operation "ReportWrongProviderType" is invalid. Remove operation "ReportWrongProviderType", or investigate why it is not valid.
The problem was that the Powershell didn’t like the log output being re-directed to a UNC path.
So I changed this:
$SqlOutputLog = "\\server1\d$\sql_backup\remote_backups\log\" + $ServerInstance.replace("\", "_") + "_sql_output.log"
invoke-sqlcmd -outputsqlerrors $True -ServerInstance $ServerInstance -QueryTimeout 3600 -InputFile d:\dbawork\admin\bin\sp_BackupDatabases.sql > $SqlOutputLog
to this
$SqlOutputLog = "d:\sql_backup\remote_backups\log\" + $ServerInstance.replace("\", "_") + "_sql_output.log"
invoke-sqlcmd -outputsqlerrors $True -ServerInstance $ServerInstance -QueryTimeout 3600 -InputFile d:\dbawork\admin\bin\sp_BackupDatabases.sql > $SqlOutputLog
i.e. I changed ‘\\server1\d$’ to ’d:'
I’m not sure what the root cause here was, to be honest. If time ever allows I’ll do some investigation.
how to see veeam backups in powershell
This allows you to see veeam backups for a specified server over the last week.
The code
Enter-PSSession yourveeamserver
Add-PSSnapin VeeamPSSnapIn
Get-VBRBackupSession | ? JobName -like "*yourtargetserver*" | ? endtime -gt $(get-date).adddays(-7) |
select jobname, jobtype, creationtime, endtime, result, state | sort-object -property jobname, endtime |
ft -AutoSize
Explanation
Explaining this a little…..
This line ‘remotes’ to the veeam server. Getting Powershell remoting set-up is another subject. I’d recommend the Powershell help topic about_remote_troubleshooting, if it doesn’t ‘just work’.
Enter-PSSession yourveeamserver
This loads all the veeam cmdlets into memory
Add-PSSnapin VeeamPSSnapIn
This line depends on your Veeam job having the name of the server you’re interested in, in the title. You can run a command to show which job backs up which database. I’ll perhaps post that soon.
Get-VBRBackupSession | ? JobName -like "*yourtargetserver*" | ? endtime -gt $(get-date).adddays(-7) |
select jobname, jobtype, creationtime, endtime, result, state | sort-object -property jobname, endtime |
ft -AutoSize
list AD users in powershell
This shows all the users with ‘dba’ in their username. Obviously you could leave out the filter clause altogether to get a complete list of AD users
Get-ADUser -Filter {samaccountname -like "*dba*"} -SearchBase "dc=mycomp,dc=co,dc=uk" |
select samaccountname, name
samaccountname name
-------------- ----
dba_john John Hollins
dba_terry Terry Dixon
You have to ActiveDirectory Powershell module loaded