Skip to content

Instantly share code, notes, and snippets.

@SQLDBAWithABeard
Last active February 22, 2020 13:18
Show Gist options
  • Save SQLDBAWithABeard/6f911ae171528181d226a11e9a24ad05 to your computer and use it in GitHub Desktop.
Save SQLDBAWithABeard/6f911ae171528181d226a11e9a24ad05 to your computer and use it in GitHub Desktop.
Pester wont run
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pester won't install in a .NET Notebook\n",
"\n",
"This notebook shows what happens when you try to run Pester in a .NET Notebook\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre>Describe: \r\n",
"Line |\r\n",
" 3 | Describe &quot;Checking Problem ...... by $($ENV:USERDOMAIN) $($ENV:UserName)&quot; {\r\n",
"\r\n",
" | ^ The &#39;Describe&#39; command was found in the module &#39;Pester&#39;, but the module could not be loaded. For more information, run &#39;Import-Module Pester&#39;.</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"## <----- Press this button - DONT MAKE A BEARD MAD BY CHANGING ANYTHING below here\n",
"\n",
"Describe \"Checking Problem ...... by $($ENV:USERDOMAIN) $($ENV:UserName)\" {\n",
" Context \" Are all the services running ?\" {\n",
" $Services = 'Audiosrv','BITS','com.docker.service','EventLog','MSSQLSERVER', 'Spooler'\n",
" foreach($Service in $Services){\n",
" It \"The Service $Service should be running\" {\n",
" (Get-Service -ComputerName localhost -Name $Service).Status | Should -Be 'Running' -Because \"Service XXXX requires the service $Service to be running\"\n",
" }\n",
" }\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"OK, lets try to import the Pester Module"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre>Get-Command: C:\\Users\\mrrob\\Documents\\PowerShell\\Modules\\Pester\\4.9.0\\Pester.psm1\r\n",
"Line |\r\n",
" 94 | $script:SafeCommands[&#39;Get-CimInstance&#39;] = Get-Command -Name Get-CimInstance -Module CimCmdlets @safeCommandLookupParameters\r\n",
"\r\n",
" | ^ The term &#39;Get-CimInstance&#39; is not recognized as the name of a\r\n",
" | cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,\r\n",
" | verify that the path is correct and try again.</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre>Import-Module: The module to process &#39;Pester.psm1&#39;, listed in field &#39;ModuleToProcess/RootModule&#39; of module manifest &#39;C:\\Users\\mrrob\\Documents\\PowerShell\\Modules\\Pester\\4.9.0\\Pester.psd1&#39; was not processed because no valid module was found in any module directory.</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Import-Module Pester"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The module CimCmdlets is not available to the session"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"Get-MOdule CimCmdlets -ListAvailable"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can import it from the local PowerShell 7 installation"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"IPMO 'C:\\program files\\powershell\\7-preview\\Modules\\CimCmdlets\\CimCmdlets.psd1'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and now Pester will import without errors"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"ipmo Pester"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and we can run a Pester Test :-)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre></pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre>Describing Checking Problem ...... by BEARDXPS mrrob</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre></pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> Context Are all the services running ?</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> [+] The Service Audiosrv should be running</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> 88ms</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> [-] The Service BITS should be running</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> 24ms</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> Expected &#39;Running&#39;, because Service XXXX requires the service BITS to be running, but got Stopped.</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> 6: (Get-Service -Name $Service).Status | Should -Be &#39;Running&#39; -Because &quot;Service XXXX requires the service $Service to be running&quot;</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> [+] The Service com.docker.service should be running</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> 3ms</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> [+] The Service EventLog should be running</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> 4ms</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> [-] The Service MSSQLSERVER should be running</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> 7ms</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> Expected &#39;Running&#39;, because Service XXXX requires the service MSSQLSERVER to be running, but got Stopped.</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> 6: (Get-Service -Name $Service).Status | Should -Be &#39;Running&#39; -Because &quot;Service XXXX requires the service $Service to be running&quot;</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> [+] The Service Spooler should be running</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre> 4ms</pre>\r\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Describe \"Checking Problem ...... by $($ENV:USERDOMAIN) $($ENV:UserName)\" {\n",
" Context \" Are all the services running ?\" {\n",
" $Services = 'Audiosrv','BITS','com.docker.service','EventLog','MSSQLSERVER', 'Spooler'\n",
" foreach($Service in $Services){\n",
" It \"The Service $Service should be running\" {\n",
" (Get-Service -Name $Service).Status | Should -Be 'Running' -Because \"Service XXXX requires the service $Service to be running\"\n",
" }\n",
" }\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (PowerShell)",
"language": "PowerShell",
"name": ".net-powershell"
},
"language_info": {
"file_extension": ".ps1",
"mimetype": "text/x-powershell",
"name": "PowerShell",
"pygments_lexer": "powershell",
"version": "7.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment