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""}}
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…
Get day of week number in cmd (dos)
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%
Get day of week number in cmd (dos)
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%
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
if the beatles used adele's naming system for their albums...
Adele has so far used her age as the title of her LPs. So, her LPs have been called:
- 19
- 21
- 25
Using Paul’s age for the album title, I think the Beatles albums would have been as follows:
- 20
- 21
- 22
- 22 (again)
- 23
- 23 (again)
- 24
- 24 (again)
- 26
- 26 (again)
- 27
- 27 (again)
Release date | Paul's age | Album name | Adele-system Album name |
---|---|---|---|
22/03/63 | 20.7 | Please Please Me (Mono) | 20 |
22/11/63 | 21.4 | With the Beatles | 21 |
10/07/64 | 22.0 | A Hard Day's Night | 22 |
4/12/64 | 22.4 | Beatles For Sale | 22 |
6/08/65 | 23.1 | Help ! | 23 |
3/12/65 | 23.4 | Rubber Soul | 23 |
5/08/66 | 24.1 | Revolver | 24 |
1/06/67 | 24.9 | Sgt. Pepper's Lonely Hearts Club Band | 24 |
22/11/68 | 26.4 | The White Album | 26 |
17/01/69 | 26.6 | Yellow Submarine | 26 |
26/09/69 | 27.2 | Abbey Road | 27 |
8/05/70 | 27.9 | Let It Be | 27 |
Paul’s date of birth was 18 June 1942
The release dates are taken from The Beatles Albums (by Date)
Pic: By The_Fabs.JPG: United Press International (UPI Telephoto)Cropping and retouching: User:Indopug and User:Misterweissderivative work: Zakke (The_Fabs.JPG) [Public domain], via Wikimedia Commons
'properties' option is greyed out for ssrs instance when you right-click in ssms
To adjust some of the properties of a SQL Server Reporting Services instance , for example, how long the execution logs are retained, or whether or not you display meaningful error messages to the user, you have to do the following:
- go into SQL Server Management Studio,
- connect to the SSRS instance, then
- right-click on the instance name and
- select Properties from the drop-down menu
However 9 times out of 10 when I do this (in my defence, I don’t do it very often….) I find that properties is greyed out, despite having logged on as a privileged user.
The ‘fix’ for this is fairly straightforward - you have to run SSMS with ‘Run as Administrator’ i.e. right-click on the SSMS icon or menu option and opt to ‘Run as Administrator’
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
how to get a list of images uploaded to wordpress.com website
-
Go to your media library and switch to the ‘List View’
-
Then under ‘Screen Options’ bump up the ‘Number of items per page’ to a big number
-
Right click to ‘View Page Source, then save it somewhere on your computer
-
Run the following in PowerShell
foreach ($line in select-string filename .\upload.php | Sort-Object -Property line ) {
$line.line.split(">")[3].split("<")[0]
}
This gives you a list that looks like this:
how to get a list of images uploaded to wordpress.com website
-
Go to your media library and switch to the ‘List View’
-
Then under ‘Screen Options’ bump up the ‘Number of items per page’ to a big number
-
Right click to ‘View Page Source, then save it somewhere on your computer
-
Run the following in PowerShell
foreach ($line in select-string filename .\upload.php | Sort-Object -Property line ) {
$line.line.split(">")[3].split("<")[0]
}
This gives you a list that looks like this:
listing database roles granted to database users in sqlserver
The output from this is unlovely, but it does the trick for the time being.
$DatabaseUsers = dir Sqlserver:\sql\$ServerName\$InstanceName\databases\$DatabaseName\Users
foreach ($User in $DatabaseUsers) {
"==$User=="
$User.EnumRoles()
}
The output looks like this
==[Company\service_account]==
RSExecRole
db_owner
==[Company\user1]==
RSExecRole
db_owner
db_accessadmin
db_securityadmin
db_ddladmin
db_backupoperator
db_datareader
db_datawriter
==[user2]==
==[user3]==
RSExecRole
db_owner
db_ddladmin
db_datareader
db_datawriter