Skip to content

Commit 1e6d4ed

Browse files
committedNov 9, 2016
update
1 parent a8d0a50 commit 1e6d4ed

File tree

3 files changed

+338
-0
lines changed

3 files changed

+338
-0
lines changed
 

‎Pester/PesterTest.psm1

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#requires -Module Pester
2+
3+
function Start-PesterTest
4+
{
5+
[CmdletBinding()]
6+
param
7+
(
8+
[Parameter(Mandatory)]
9+
[ValidateNotNullOrEmpty()]
10+
[string]$Module,
11+
12+
[Parameter(Mandatory)]
13+
[ValidateNotNullOrEmpty()]
14+
[ValidateSet('Unit','Integration','Acceptance')]
15+
[string]$Type,
16+
17+
[Parameter()]
18+
[string]$TestName,
19+
20+
[Parameter()]
21+
[hashtable]$AdditionalParams
22+
)
23+
begin
24+
{
25+
$ErrorActionPreference = 'Stop'
26+
}
27+
process
28+
{
29+
try
30+
{
31+
if (-not ($testScript = Find-TestScript -Module $Module -Type $Type)) {
32+
throw "Could not find $Type test script for the [$($Module)] module."
33+
} else {
34+
$invPestParams = @{
35+
Path = $testScript.FullName
36+
}
37+
if ($PSBoundParameters.ContainsKey('InvokePesterParams'))
38+
{
39+
$invPestParams += $AdditionalParams
40+
}
41+
if ($PSBoundParameters.ContainsKey('TestName'))
42+
{
43+
$invPestParams.TestName = $TestName
44+
}
45+
Invoke-Pester @invPestParams
46+
47+
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Invoke-Pester', [System.Management.Automation.CommandTypes]::Function)
48+
$scriptCmd = { & $wrappedCmd @invPestParams }
49+
$steppablePipeline = $scriptCmd.GetSteppablePipeline()
50+
$steppablePipeline.Begin($PSCmdlet)
51+
}
52+
}
53+
catch
54+
{
55+
$PSCmdlet.ThrowTerminatingError($_)
56+
}
57+
}
58+
}
59+
60+
function Find-TestScript
61+
{
62+
[OutputType([System.IO.FileInfo])]
63+
[CmdletBinding()]
64+
param
65+
(
66+
[Parameter(Mandatory)]
67+
[ValidateNotNullOrEmpty()]
68+
[string]$Module,
69+
70+
[Parameter(Mandatory)]
71+
[ValidateNotNullOrEmpty()]
72+
[ValidateSet('Unit','Integration','Acceptance')]
73+
[string]$Type
74+
)
75+
76+
Get-ChildItem -Path 'C:\Program Files\WindowsPowerShell\Modules' -Filter "$Module.$Type.Tests.ps1"
77+
}
78+
79+
function Start-UnitTest
80+
{
81+
[CmdletBinding()]
82+
param
83+
(
84+
[Parameter(Mandatory)]
85+
[ValidateNotNullOrEmpty()]
86+
[string]$Module,
87+
88+
[Parameter()]
89+
[ValidateNotNullOrEmpty()]
90+
[string]$TestName,
91+
92+
[Parameter()]
93+
[ValidateNotNullOrEmpty()]
94+
[hashtable]$AdditionalParams
95+
)
96+
$params = @{
97+
Module = $Module
98+
Type = 'Unit'
99+
TestName = $TestName
100+
InvokePesterParams = $AdditionalParams
101+
}
102+
Start-PesterTest @params
103+
}
104+
105+
function Start-IntegrationTest
106+
{
107+
[CmdletBinding()]
108+
param
109+
(
110+
[Parameter(Mandatory)]
111+
[ValidateNotNullOrEmpty()]
112+
[string]$Module,
113+
114+
[Parameter()]
115+
[ValidateNotNullOrEmpty()]
116+
[string]$TestName,
117+
118+
[Parameter()]
119+
[ValidateNotNullOrEmpty()]
120+
[hashtable]$AdditionalParams
121+
)
122+
$params = @{
123+
Module = $Module
124+
Type = 'Integration'
125+
TestName = $TestName
126+
InvokePesterParams = $AdditionalParams
127+
}
128+
Start-PesterTest @params
129+
}
130+
131+
function Start-AcceptanceTest
132+
{
133+
[CmdletBinding()]
134+
param
135+
(
136+
[Parameter(Mandatory)]
137+
[ValidateNotNullOrEmpty()]
138+
[string]$Module,
139+
140+
[Parameter()]
141+
[ValidateNotNullOrEmpty()]
142+
[string]$TestName,
143+
144+
[Parameter()]
145+
[ValidateNotNullOrEmpty()]
146+
[hashtable]$AdditionalParams
147+
)
148+
$params = @{
149+
Module = $Module
150+
Type = 'Acceptance'
151+
TestName = $TestName
152+
InvokePesterParams = $AdditionalParams
153+
}
154+
Start-PesterTest @params
155+
}

‎Random Stuff/Get-Weather.ps1

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#requires -Version 4
2+
3+
function Get-WeatherForecast
4+
{
5+
[OutputType([pscustomobject])]
6+
[CmdletBinding()]
7+
param
8+
(
9+
[Parameter(Mandatory)]
10+
[ValidateNotNullOrEmpty()]
11+
[ValidatePattern('^\d{5}$')]
12+
[int]$ZipCode,
13+
14+
[Parameter()]
15+
[ValidateNotNullOrEmpty()]
16+
[int]$DaysOut = 7
17+
)
18+
begin
19+
{
20+
$ErrorActionPreference = 'Stop'
21+
}
22+
process
23+
{
24+
try
25+
{
26+
$uri = 'http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl'
27+
$proxy = New-WebServiceProxy -uri $uri -namespace WebServiceProxy
28+
$latlon = $proxy.LatLonListZipCode($ZipCode)
29+
@($latlon).foreach({
30+
$l = $_
31+
$a = $l.dwml.latlonlist -split ','
32+
$lat = $a[0]
33+
$lon = $a[1]
34+
$now = get-date -UFormat %Y-%m-%d
35+
$format = 'Item24hourly'
36+
$weather = $Proxy.NDFDgenByDay($lat,$lon,$now,$DaysOut,$format)
37+
for ($i = 0 ; $i -le $DaysOut - 1; $i++) {
38+
[pscustomobject]@{
39+
Date = ((Get-Date).addDays($i)).tostring(MM/dd/yyyy) ;
40+
maxTemp = $weather.dwml.data.parameters.temperature[0].value[$i] ;
41+
minTemp = $weather.dwml.data.parameters.temperature[1].value[$i] ;
42+
Summary = $weather.dwml.data.parameters.weather.weather-conditions[$i].Weather-summary
43+
}
44+
}
45+
})
46+
}
47+
catch
48+
{
49+
$PSCmdlet.ThrowTerminatingError($_)
50+
}
51+
}
52+
}

‎Windows Install/AutoUnattend.xml

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<unattend xmlns="urn:schemas-microsoft-com:unattend">
3+
<settings pass="windowsPE">
4+
<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<SetupUILanguage>
6+
<UILanguage>en-US</UILanguage>
7+
</SetupUILanguage>
8+
<InputLocale>en-US</InputLocale>
9+
<SystemLocale>en-US</SystemLocale>
10+
<UILanguage>en-US</UILanguage>
11+
<UserLocale>en-US</UserLocale>
12+
</component>
13+
<component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
14+
<DiskConfiguration>
15+
<Disk wcm:action="add">
16+
<CreatePartitions>
17+
<!-- System partition -->
18+
<CreatePartition wcm:action="add">
19+
<Order>1</Order>
20+
<Size>350</Size>
21+
<Type>Primary</Type>
22+
</CreatePartition>
23+
<!-- Windows partition -->
24+
<CreatePartition wcm:action="add">
25+
<Order>2</Order>
26+
<Extend>true</Extend>
27+
<Type>Primary</Type>
28+
</CreatePartition>
29+
</CreatePartitions>
30+
<ModifyPartitions>
31+
<ModifyPartition wcm:action="add">
32+
<Order>1</Order>
33+
<PartitionID>1</PartitionID>
34+
<Label>System</Label>
35+
<Format>NTFS</Format>
36+
<Active>true</Active>
37+
</ModifyPartition>
38+
<ModifyPartition wcm:action="add">
39+
<Order>2</Order>
40+
<PartitionID>2</PartitionID>
41+
<Format>NTFS</Format>
42+
<Label>Windows</Label>
43+
</ModifyPartition>
44+
</ModifyPartitions>
45+
<DiskID>0</DiskID>
46+
<WillWipeDisk>true</WillWipeDisk>
47+
</Disk>
48+
<WillShowUI>OnError</WillShowUI>
49+
</DiskConfiguration>
50+
<ImageInstall>
51+
<OSImage wcm:action="add">
52+
<InstallTo>
53+
<DiskID>0</DiskID>
54+
<PartitionID>2</PartitionID>
55+
</InstallTo>
56+
<InstallFrom>
57+
<MetaData wcm:action="add">
58+
<Value>Windows Server 2012 R2 SERVERSTANDARD</Value>
59+
<Key>/IMAGE/NAME</Key>
60+
</MetaData>
61+
</InstallFrom>
62+
<InstallToAvailablePartition>false</InstallToAvailablePartition>
63+
</OSImage>
64+
</ImageInstall>
65+
<UserData>
66+
<ProductKey>
67+
<WillShowUI>OnError</WillShowUI>
68+
<Key>PNCRQ-TYDVC-QC8X9-Y24Q3-3PC2B</Key>
69+
</ProductKey>
70+
<AcceptEula>true</AcceptEula>
71+
</UserData>
72+
</component>
73+
</settings>
74+
<settings pass="specialize">
75+
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
76+
<ComputerName>TESTDC</ComputerName>
77+
<RegisteredOwner>Adam Bertram</RegisteredOwner>
78+
<AutoLogon>
79+
<Password>
80+
<Value>cABAACQAJAB3ADAAcgBkADEAMgBQAGEAcwBzAHcAbwByAGQA</Value>
81+
<PlainText>false</PlainText>
82+
</Password>
83+
<Enabled>true</Enabled>
84+
<Username>Administrator</Username>
85+
</AutoLogon>
86+
</component>
87+
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
88+
<RunSynchronous>
89+
<RunSynchronousCommand wcm:action="add">
90+
<Order>2</Order>
91+
<Path>cmd /c net user administrator /active:yes</Path>
92+
<Description>enable administrator</Description>
93+
</RunSynchronousCommand>
94+
<RunSynchronousCommand wcm:action="add">
95+
<Order>3</Order>
96+
<Description>Set NIC IP and DNS</Description>
97+
<Path>powershell -NoProfile -Command &quot;$i=(Get-NetAdapter).ifIndex;New-NetIPAddress -IPAddress &apos;192.168.0.156&apos; -PrefixLength 24 -InterfaceIndex $i;Set-DnsClientServerAddress -InterfaceIndex $i -ServerAddresses &apos;192.168.0.156&apos;&quot;</Path>
98+
</RunSynchronousCommand>
99+
<RunSynchronousCommand wcm:action="add">
100+
<Order>4</Order>
101+
<Description>Disable Firewall</Description>
102+
<Path>NetSh Advfirewall set allprofiles state off</Path>
103+
</RunSynchronousCommand>
104+
<RunSynchronousCommand wcm:action="add">
105+
<Path>cmd /c reg add &quot;HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell&quot; /v ExecutionPolicy /t REG_SZ /d Unrestricted /f</Path>
106+
<Description>Configure Powershell security settings</Description>
107+
<Order>1</Order>
108+
</RunSynchronousCommand>
109+
</RunSynchronous>
110+
</component>
111+
</settings>
112+
<settings pass="oobeSystem">
113+
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
114+
<UserAccounts>
115+
<AdministratorPassword>
116+
<Value>cABAACQAJAB3ADAAcgBkADEAMgBBAGQAbQBpAG4AaQBzAHQAcgBhAHQAbwByAFAAYQBzAHMAdwBvAHIAZAA=</Value>
117+
<PlainText>false</PlainText>
118+
</AdministratorPassword>
119+
</UserAccounts>
120+
<AutoLogon>
121+
<Password>
122+
<Value>cABAACQAJAB3ADAAcgBkADEAMgBQAGEAcwBzAHcAbwByAGQA</Value>
123+
<PlainText>false</PlainText>
124+
</Password>
125+
<Enabled>true</Enabled>
126+
<Username>administrator</Username>
127+
</AutoLogon>
128+
</component>
129+
</settings>
130+
<cpi:offlineImage cpi:source="wim:c:/en_windows_server_2012_r2_with_update_x64_dvd_4065220/sources/install.wim#Windows Server 2012 R2 SERVERSTANDARD" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
131+
</unattend>

0 commit comments

Comments
 (0)
Please sign in to comment.