full_path
stringlengths
31
232
filename
stringlengths
4
167
content
stringlengths
0
48.3M
PowerShellCorpus/Github/naeemkhedarun_Console/Install/Scripts/Mixed Platform/Console/Keyboard Shortcut.ps1
Keyboard Shortcut.ps1
$consoleShortcutFolder = Join-Path ([Environment]::GetFolderPath("StartMenu")) "_consoleHotkeys" if (Test-Path $consoleShortcutFolder) { Remove-Item $consoleShortcutFolder -Force -Recurse } New-Item $consoleShortcutFolder -Type Directory -Force | Out-Null $WshShell = New-Object -ComObject WScript.Shell Invok...
PowerShellCorpus/Github/naeemkhedarun_Console/Install/Scripts/Specific Platform/ExecutionPolicy.ps1
ExecutionPolicy.ps1
Invoke-InstallStep "Setting ExecutionPolicy to RemoteSigned" { Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine }
PowerShellCorpus/Github/naeemkhedarun_Console/Install/Scripts/Install Helpers/Invoke-InstallStep.ps1
Invoke-InstallStep.ps1
function Invoke-InstallStep { [CmdletBinding()] param ( [switch]$EnterNewScope, [Parameter(Mandatory=$true)]$InstallMessage, [Parameter(Mandatory=$true)]$InstallStep ) Write-Host -NoNewline ("{0}$InstallMessage... " -f ("`t" * $global:MessageScope)) try { & $InstallStep } catch { Write-...
PowerShellCorpus/Github/naeemkhedarun_Console/Install/Scripts/Install Helpers/Exit-Scope.ps1
Exit-Scope.ps1
function Exit-Scope { $global:MessageScope-- }
PowerShellCorpus/Github/naeemkhedarun_Console/Install/Scripts/Install Helpers/Write-InstallMessage.ps1
Write-InstallMessage.ps1
function Write-InstallMessage { [CmdletBinding(DefaultParameterSetName="Default")] param ( [Parameter(Mandatory=$true)]$InstallMessage, [ValidateSet("Default","Success","Warning","Error")] $Type = "Default", [switch]$EnterNewScope ) switch ($Type) { "Default" { Write-Host ("{0}$InstallMes...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/InternalHelpers/New-ProfileConfig.ps1
New-ProfileConfig.ps1
function New-ProfileConfig { param($overrideProfileConfig) $o = $overrideProfileConfig $ProfileConfig = @{ General = @{ InstallPath = $InstallPath ProfileConfigFile = $profileConfigFile PowerShellScriptsFolder = (Join-Path ([System.Environment]::GetFolderPath("MyDocuments")) "PowerShell Scrip...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/InternalHelpers/Initialize-ProfileConfig.ps1
Initialize-ProfileConfig.ps1
function Initialize-ProfileConfig { if (Test-Path $profileConfigFile) { $importedProfileConfig = Import-Clixml $profileConfigFile } $ProfileConfig = New-ProfileConfig $importedProfileConfig Register-EngineEvent -SourceIdentifier PowerShell.Exiting -SupportEvent -Action { $Profi...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Convert-Temperature.ps1
Convert-Temperature.ps1
function Convert-Temperature { [CmdletBinding()] param( [Parameter(Mandatory=$true)][double]$Temperature, [Parameter(Mandatory=$true)][string][ValidateSet("C", "F", "K")]$From, [Parameter(Mandatory=$true)][string][ValidateSet("C", "F", "K")]$To ) switch ($From) { "C" {$data = $Temperature} "F"...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Get-Type.ps1
Get-Type.ps1
filter Get-Type { $_ | ? { $null -ne $_ } | % { $_.GetType() } } @{Function = "Get-Type"}
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Invoke-ReverseDnsLookup.ps1
Invoke-ReverseDnsLookup.ps1
function Invoke-ReverseDnsLookup { <# .SYNOPSIS Perform a reverse DNS lookup scan on a range of IP addresses. PowerSploit Function: Invoke-ReverseDnsLookup Author: Matthew Graeber (@mattifestation) License: BSD 3-Clause Required Dependencies: None Optional Dependencies: None .DESCRIPTION Invoke-Reve...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/UnProtect-File.ps1
UnProtect-File.ps1
function UnProtect-File { [CmdletBinding()] param( [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][ValidateScript({Test-Path $_})] $path, [System.Security.Cryptography.DataProtectionScope] $scope = [System.Security.Cryptography.DataProtectionScope]::CurrentUser, [Parameter(Param...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Custom Prompt.ps1
Custom Prompt.ps1
Set-Alias prompt Write-CustomPrompt function Write-CustomPrompt { $realLASTEXITCODE = $LASTEXITCODE $windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $windowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal $windowsIdentity if ($windowsPrincipal.IsInRole([...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Show-PressAnyKeyToContinue.ps1
Show-PressAnyKeyToContinue.ps1
function Show-PressAnyKeyToContinue { Write-Host -NoNewLine "Press any key to continue . . . " $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null Write-Host } @{Function = "Show-PressAnyKeyToContinue"}
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Touch-File.ps1
Touch-File.ps1
Set-Alias touch Set-File function Set-File { param ( [Parameter(Mandatory=$true)]$path, $content = $null, $time = (Get-Date) ) if (-not (Test-Path $path) -or ((Test-Path $path) -and $null -ne $content)) { Set-Content -Path $path -Value $content } Se...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Find-FileOrFolder.ps1
Find-FileOrFolder.ps1
function Find-FileOrFolder { [CmdletBinding()] param( [Parameter(Position=0,Mandatory=$true)]$name, $path = $pwd, [switch]$partialName ) if ($partialName) { $name = "*$($name)*" } Get-ChildItem -Path $path -Recurse -Filter $name | % { Resolve-Path -Relative $_.FullName } } @{Function = "Fi...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Clear-PSBreakpoint.ps1
Clear-PSBreakpoint.ps1
Set-Alias cbp Clear-PSBreakpoint function Clear-PSBreakpoint { Get-PSBreakpoint | Remove-PSBreakpoint } @{Function = "Clear-PSBreakpoint"; Alias = "cbp"}
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Restart-Console.ps1
Restart-Console.ps1
function Restart-Console { Start-Process -FilePath "$InstallPath\Third Party\Console\ConEmu64.exe" -ArgumentList "/cmd powershell.exe" -WorkingDirectory $pwd Exit } @{Function = "Restart-Console"}
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Add-DllImport.ps1
Add-DllImport.ps1
function Add-DllImport { [CmdletBinding()] param ( [Parameter(Mandatory=$true)]$dll, [Parameter(Mandatory=$true)]$returnType, [Parameter(Mandatory=$true)]$methodName, [Parameter(Mandatory=$true)]$parameters ) $decodedParameters = $parameters | Join-String -Separator '...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Open-UrlWithDefaultBrowser.ps1
Open-UrlWithDefaultBrowser.ps1
function GetCommandTemplate { [CmdletBinding()] param ( [Parameter(Mandatory=$true)]$defaultBrowserProgId ) $Shlwapi = Add-DllImport -dll "Shlwapi" -returnType "int" -methodName "AssocQueryString" -parameters @("int flags", "int str", "string pszAssoc", "string pszExtra", "ref char[] pszOut"...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/New-DynamicModuleBuilder.ps1
New-DynamicModuleBuilder.ps1
function New-DynamicModuleBuilder { # .SYNOPSIS # Creates a new assembly and a dynamic module within the current AppDomain. # .DESCRIPTION # Prepares a System.Reflection.Emit.ModuleBuilder class to allow construction of dynamic types. The ModuleBuilder is created to allow the creation of multiple types ...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Start-PowerShell.ps1
Start-PowerShell.ps1
function Start-PowerShell { [CmdletBinding()] param( [ValidateSet("Native", "32bit", "64bit")]$Bitness = "Native", [Parameter(ValueFromRemainingArguments=$true)]$Switches ) $64bitOs = [System.Environment]::Is64BitOperatingSystem $32bitOs = -not $64bitOs $64bitProcess = ...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Open-Location.ps1
Open-Location.ps1
Set-Alias browse Open-Location function Open-Location { [CmdletBinding()] param( [ValidateSet("InstallPath", "ProfileModule", "Profile", "CurrentDirectory", "PowerShellScripts", "Scripts", "Documents", "Desktop", "Computer", "GitHub")] [Parameter(Position = 1)]$location = "CurrentDirectory"...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Open-Superuser.ps1
Open-Superuser.ps1
Set-Alias su Open-Superuser function Open-Superuser { Start-Process -FilePath "$InstallPath\Third Party\Console\ConEmu64.exe" -ArgumentList "/cmd powershell.exe -cur_console:na" -WorkingDirectory $pwd Exit } @{Function = "Open-Superuser"; Alias = "su"}
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Invoke-Portscan.ps1
Invoke-Portscan.ps1
function Invoke-Portscan { <# .SYNOPSIS Simple portscan module PowerSploit Function: Invoke-Portscan Author: Rich Lundeen (http://webstersProdigy.net) License: BSD 3-Clause Required Dependencies: None Optional Dependencies: None .DESCRIPTION Does a simple port scan using regular sockets, based (prett...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/UnProtect-String.ps1
UnProtect-String.ps1
function UnProtect-String { [CmdletBinding()] param( [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][string]$encryptedString, [System.Security.Cryptography.DataProtectionScope]$scope = [System.Security.Cryptography.DataProtectionScope]::CurrentUser ) $encryptedBytes = [Convert]::F...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Enable-Debug.ps1
Enable-Debug.ps1
function Enable-Debug { [CmdletBinding()] $Global:DebugPreference = "Continue" $Global:VerbosePreference = "Continue" } @{Function = "Enable-Debug"}
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Protect-String.ps1
Protect-String.ps1
function Protect-String { [CmdletBinding()] param( [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][string]$string, [System.Security.Cryptography.DataProtectionScope]$scope = [System.Security.Cryptography.DataProtectionScope]::CurrentUser ) $unEncryptedBytes = [System.Text.Encoding]...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Invoke-WindowsApi.ps1
Invoke-WindowsApi.ps1
function Invoke-WindowsApi { ############################################################################## ## ## Invoke-WindowsApi ## ## From Windows PowerShell Cookbook (O'Reilly) ## by Lee Holmes (http://www.leeholmes.com/guide) ## ########################################...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/New-Enum.ps1
New-Enum.ps1
function New-Enum { [CmdLetBinding()] param( [Parameter(Mandatory = $true)] [ValidatePattern('^(\w+\.)*\w+$')] [String]$Name, [Alias('Flags')] [Switch]$SetFlagsAttribute, [Parameter(Mandatory = $true)] [array]$Members ) if ($SetFlagsAttribute) { $flagsAttribute = ...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Disable-Debug.ps1
Disable-Debug.ps1
function Disable-Debug { [CmdletBinding()] $Global:DebugPreference = "SilentlyContinue" $Global:VerbosePreference = "SilentlyContinue" } @{Function = "Disable-Debug"}
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Invoke-Remote.ps1
Invoke-Remote.ps1
Set-Alias remote Invoke-Remote function Invoke-Remote { [CmdletBinding(DefaultParameterSetName="Interactive")] param( [Parameter(Mandatory=$true,Position=0)] $ComputerName, [ValidateSet("PowerShell", "RDC", "RDP")][Parameter(ParameterSetName="Interactive",Position=1)] $Int...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Protect-File.ps1
Protect-File.ps1
function Protect-File { [CmdletBinding()] param( [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][ValidateScript({Test-Path $_})] $path, [System.Security.Cryptography.DataProtectionScope] $scope = [System.Security.Cryptography.DataProtectionScope]::CurrentUser, [Parameter(Paramet...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Find-String.ps1
Find-String.ps1
function Find-String { [CmdletBinding()] param( [Parameter(Position=0,Mandatory=$true)]$pattern, $path = $pwd, $exclude = @("*.exe", "*.dll"), [switch]$showContext, [switch]$includeLargeFiles ) $maxFileSizeToSearchInBytes = 1024*1024 # 1mb Write-Host "Finding '$pattern' in $path...`n...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/Publish-ConsoleToGitHub.ps1
Publish-ConsoleToGitHub.ps1
function Publish-ConsoleToGitHub { [CmdletBinding(DefaultParameterSetName = "Commit")] param( [Parameter(ParameterSetName = "Status")][switch]$status, [Parameter(ParameterSetName = "Discard")][switch]$discardChanges, [Parameter(ParameterSetName = "Commit", Position = 1)]$commitMessage, [Parameter(Parame...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/ActiveDirectory/Get-UsersActiveDirectoryGroups.ps1
Get-UsersActiveDirectoryGroups.ps1
function Get-UsersActiveDirectoryGroups { [CmdletBinding()] param ( [Parameter()]$username = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name, [Parameter()]$comparisonUsername ) Add-Type -AssemblyName System.DirectoryServices.AccountManagement $ct = [System.DirectorySe...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/EMail/Send-Note.ps1
Send-Note.ps1
function Send-Note { [CmdletBinding()] param( [Parameter(Mandatory=$true)][ValidateSet("Work", "Home")]$To, [Parameter(Mandatory=$true,ValueFromRemainingArguments=$true)][string]$Body ) $password = ConvertTo-SecureString $ProfileConfig.EMail.Password $credential = New-Object Syste...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/EMail/Set-Email.ps1
Set-Email.ps1
function Set-Email { [CmdletBinding()] param( [Parameter(Mandatory=$true)]$EmailServer, [Parameter(Mandatory=$true)]$From, [Parameter(Mandatory=$true)]$Username ) $password = Read-Host "Enter the password for the '$Username'" -AsSecureString $ProfileConfig.PowerShell.PSEm...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/EMail/Send-Email.ps1
Send-Email.ps1
function Send-Email { [CmdletBinding()] param( [Parameter(Mandatory=$true)]$To, [Parameter(Mandatory=$true)]$Subject, [Parameter(Mandatory=$true)]$Body ) $password = ConvertTo-SecureString $ProfileConfig.EMail.Password $credential = New-Object System.Management.Automat...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/TFS/Get-VersionControlServer.ps1
Get-VersionControlServer.ps1
function Get-VersionControlServer { [CmdletBinding()] param ( $tfsServerUrl = $ProfileConfig.TFS.Server ) if ($tfsServerUrl -eq $null) { Write-Error "No TFS Server URL Given" } [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") | Out-Null [System.Reflection.A...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/TFS/Get-QueuedBuilds.ps1
Get-QueuedBuilds.ps1
function Get-QueuedBuilds { $buildServer = Get-BuildServer $buildsRunningOnAgents = 0 $buildServer.QueryBuildAgents($buildServer.CreateBuildAgentSpec()).Agents | % { $buildOnAgent = $null if ($_.ReservedForBuild) { $buildOnAgent = $buildServer.GetBuild($_.ReservedForBuild) $buildsRunningOnAgents+...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/TFS/Get-BuildServer.ps1
Get-BuildServer.ps1
function Get-BuildServer { [CmdletBinding()] param ( $tfsServerUrl = $ProfileConfig.TFS.Server ) if ($tfsServerUrl -eq $null) { Write-Error "No TFS Server URL Given" } [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") | Out-Null [System.Reflection.Assembly]:...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Exports/TFS/TfsTeamProjects.ps1
TfsTeamProjects.ps1
function Get-TfsTeamProjects { Get-VersionControlServer | % { $_.GetAllTeamProjects($true) } | % { $_.Name } } @{Function = "Get-TfsTeamProjects"}
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Configure/Create PSDrives.ps1
Create PSDrives.ps1
# HKEY_CLASSES_ROOT or HKCR Remove-PSDrive -Name HKCR -ErrorAction SilentlyContinue New-PSDrive -PSProvider Registry -Root HKEY_CLASSES_ROOT -Name HKCR -Scope Global | Out-Null # HKEY_CURRENT_USER or HKCU # Setup by default # HKEY_LOCAL_MACHINE or HKLM # Setup by default # HKEY_USERS or HKU Remove-PSDrive...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Configure/1 - Configure Environment Variables.ps1
1 - Configure Environment Variables.ps1
# Update PATH to reference 'Binaries' directory and subdirectories $env:Path += ";" + (Join-Path $InstallPath "Third Party\Binaries") + ";" + ((Get-ChildItem (Join-Path $InstallPath "Third Party\Binaries") | Where {$_.psIsContainer} | Select -expandProperty FullName) -join ";") $env:Path = $env:Path.Trim(';') # Up...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Configure/Import Visual Studio Vars.ps1
Import Visual Studio Vars.ps1
#Import-VisualStudioVars 2013
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Configure/Configure Git.ps1
Configure Git.ps1
function UpdateGit { param( [Parameter(ValueFromRemainingArguments=$true)]$config ) & git config $config user.name $ProfileConfig.Git.Name & git config $config user.email $ProfileConfig.Git.Email & git config $config core.ignorecase $True & git config $config core.autocrlf $True ...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Configure/2 - Import Default Modules.ps1
2 - Import Default Modules.ps1
# PowerShell Community Extensions - http://pscx.codeplex.com/ Import-Module Pscx -Global -ArgumentList @{ TextEditor = "$InstallPath\Third Party\Sublime Text\sublime_text.exe"; CD_EchoNewLocation = $false } # PSReadline - https://github.com/lzybkr/PSReadLine if ($host.Name -eq 'ConsoleHost') { Import-...
PowerShellCorpus/Github/naeemkhedarun_Console/Profile/Configure/Configure PowerShell.ps1
Configure PowerShell.ps1
$Global:PSEmailServer = $ProfileConfig.PowerShell.PSEmailServer $Global:FormatEnumerationLimit = $ProfileConfig.PowerShell.FormatEnumerationLimit
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Console/ConEmu/Addons/AnsiColors24bit.ps1
AnsiColors24bit.ps1
# In the current ConEmu version TrueColor is available # only in the lower part of console buffer $h = [Console]::WindowHeight $w = [Console]::BufferWidth $y = ([Console]::BufferHeight-$h) # Clean console contents (this will clean TrueColor attributes) Write-Host (([char]27)+"[9999S") # Apply default powersh...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pscx/Pscx.UserPreferences.ps1
Pscx.UserPreferences.ps1
# --------------------------------------------------------------------------- # You can override individual preferences by passing a hashtable with just those # preference defined as shown below: # # Import-Module Pscx -arg @{ModulesToImport = @{Prompt = $true}} # # Any value not specified will be retrieved f...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pscx/Modules/Prompt/Themes/Modern.ps1
Modern.ps1
# --------------------------------------------------------------------------- # Author: Keith Hill # Desc: Prompt, colors and host window title updates suited to UAC enabled # Windows Vista and Windows 7. Elevated (admin) prompts are easy # distinguish from non-elevated prompts. # Date: Nov 07...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pscx/Modules/Prompt/Themes/WinXP.ps1
WinXP.ps1
# --------------------------------------------------------------------------- # Author: Keith Hill # Desc: Prompt, colors and host window title updates suited to Windows XP # where folks tend to run with adminstrator privileges all the time. # Date: Nov 07, 2009 # Site: http://pscx.codeplex.com # Us...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pscx/Modules/Prompt/Themes/Jachym.ps1
Jachym.ps1
# --------------------------------------------------------------------------- # Author: Jachymko # Desc: Jachym's prompt, colors and host window title updates. # Date: Nov 07, 2009 # Site: http://pscx.codeplex.com # Usage: In your options hashtable place the following setting: # # PromptTheme = 'J...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/build.psake.ps1
build.psake.ps1
$psake.use_exit_on_error = $true properties { $currentDir = resolve-path . $Invocation = (Get-Variable MyInvocation -Scope 1).Value $baseDir = $psake.build_script_dir $version = git describe --abbrev=0 --tags $nugetExe = "$baseDir\vendor\tools\nuget" } Task default -depends Build Task Bui...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Examples/Validator/Validator.Tests.ps1
Validator.Tests.ps1
function MyValidator($thing_to_validate) { return $thing_to_validate.StartsWith("s") } function Invoke-SomethingThatUsesMyValidator { param( [ValidateScript({MyValidator $_})] $some_param ) } Describe "Testing a validator" { It "calls MyValidator" { Mock MyVali...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Examples/Calculator/Add-Numbers.ps1
Add-Numbers.ps1
function Add-Numbers($a, $b) { return $a + $b }
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Examples/Calculator/Add-Numbers.Tests.ps1
Add-Numbers.Tests.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path . "$here\Add-Numbers.ps1" Describe -Tags "Example" "Add-Numbers" { It "adds positive numbers" { Add-Numbers 2 3 | Should Be 5 } It "adds negative numbers" { Add-Numbers (-2) (-2) | Should Be (-4) } It "adds one ...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Validate-Xml.ps1
Validate-Xml.ps1
############################################################################################## # Taken from http://gallery.technet.microsoft.com/scriptcenter/2f6f0541-d152-4474-a8c1-b441d7424454 # Written by Justin Yancey ############################################################################################## ...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/It.Tests.ps1
It.Tests.ps1
Set-StrictMode -Version Latest function List-ExtraKeys($baseHash, $otherHash) { $extra_keys = @() $otherHash.Keys | ForEach-Object { if ( -not $baseHash.ContainsKey($_)) { $extra_keys += $_ } } return $extra_keys } Describe "It - Caller scoped tests" { It...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/TestDrive.ps1
TestDrive.ps1
# function New-TestDrive ([Switch]$PassThru) { $Path = New-RandomTempDirectory $DriveName = "TestDrive" if (-not (Test-Path -Path $Path)) { New-Item -ItemType Container -Path $Path | Out-Null } #setup the test drive if ( -not (Get-PSDrive -Name $DriveName -ErrorAction SilentlyContinue) ...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/New-Fixture.ps1
New-Fixture.ps1
function New-Fixture { <# .SYNOPSIS This function generates two scripts, one that defines a function and another one that contains its tests. .DESCRIPTION This function generates two scripts, one that defines a function and another one that contains its tests. The files are by defau...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/TestResults.ps1
TestResults.ps1
function Get-HumanTime($Seconds) { if($Seconds -gt 0.99) { $time = [math]::Round($Seconds, 2) $unit = "s" } else { $time = [math]::Floor($Seconds * 1000) $unit = "ms" } return "$time$unit" } function Export-NUnitReport { param ( [parameter(Mandato...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/TestDrive.Tests.ps1
TestDrive.Tests.ps1
Set-StrictMode -Version Latest Describe "Setup" { It "returns a location that is in a temp area" { $TestDrive -like "${$env:temp}*" | Should Be $true } It "creates a drive location called TestDrive:" { "TestDrive:\" | Should Exist } } Describe "TestDrive" { It "hand...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/InModuleScope.Tests.ps1
InModuleScope.Tests.ps1
Set-StrictMode -Version Latest Describe "Module scope separation" { Context "When users define variables with the same name as Pester parameters" { $test = "This is a test." It "does not hide user variables" { $test | Should Be 'This is a test.' } } ...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/In.Tests.ps1
In.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "the In statement" { Setup -Dir "test_path" It "executes a command in that directory" { In "$TestDrive" -Execute { "" | Out-File "test_file" } "$TestDrive\test_file" | Should Exist } ...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Coverage.ps1
Coverage.ps1
if ($PSVersionTable.PSVersion.Major -le 2) { function Exit-CoverageAnalysis { } function Get-CoverageReport { } function Show-CoverageReport { } function Enter-CoverageAnalysis { param ( $CodeCoverage ) if ($CodeCoverage) { Write-Error 'Code coverage analysis requires PowerShell...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/New-Fixture.Tests.ps1
New-Fixture.Tests.ps1
Set-StrictMode -Version Latest Describe "New-Fixture" { It "Name parameter is mandatory:" { (get-command New-Fixture ).Parameters.Name.ParameterSets.__AllParameterSets.IsMandatory | Should Be $true } Context "Only Name parameter is specified:" { It "Creates fixture in cu...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/TestResults.Tests.ps1
TestResults.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "Write nunit test results" { Setup -Dir "Results" It "should write a successful test result" { #create state $TestResults = New-PesterState -Path TestDrive:\ $testResults.EnterDescribe('Mocked Describe'...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/PesterState.ps1
PesterState.ps1
function New-PesterState { param ( [Parameter(Mandatory=$true)] [String]$Path, [String[]]$TagFilter, [String[]]$TestNameFilter, [System.Management.Automation.SessionState] $SessionState ) if ($null -eq $SessionState) { $SessionState = $ExecutionContext.SessionState } New-Module -...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/PesterState.Tests.ps1
PesterState.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "New-PesterState" { it "Path is mandatory parameter" { (get-command New-PesterState ).Parameters.Path.ParameterSets.__AllParameterSets.IsMandatory | Should Be $true } Context "Path parameter is set" { ...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Context.ps1
Context.ps1
function Context { <# .SYNOPSIS Provides syntactic sugar for logiclly grouping It blocks within a single Describe block. .PARAMETER Name The name of the Context. This is a phrase describing a set of tests within a describe. .PARAMETER Fixture Script that is executed. This may include setup specific to the co...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Mock.Tests.ps1
Mock.Tests.ps1
Set-StrictMode -Version Latest function FunctionUnderTest { [CmdletBinding()] param ( [Parameter(Mandatory=$false)] [string] $param1 ) return "I am a real world test" } function FunctionUnderTestWithoutParams([string]$param1) { return "I am a real world ...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Coverage.Tests.ps1
Coverage.Tests.ps1
if ($PSVersionTable.PSVersion.Major -le 2) { return } InModuleScope Pester { Describe 'Code Coverage Analysis' { $root = (Get-PSDrive TestDrive).Root $null = New-Item -Path $root\TestScript.ps1 -ItemType File -ErrorAction SilentlyContinue Set-Content -Path $root\TestScript.ps1 -Va...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/It.ps1
It.ps1
function It { <# .SYNOPSIS Validates the results of a test inside of a Describe block. .DESCRIPTION The It function is intended to be used inside of a Describe Block. If you are familiar with the AAA pattern (Arrange-Act-Assert), this would be the appropriate location for an assert. The convention is to as...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/In.ps1
In.ps1
function In { <# .SYNOPSIS A convenience function that executes a scrit from a specified path. .DESCRIPTION Before the script block passed to the execute parameter is invoked, the current location is set to the path specified. Once the script block has been executed, the location will be reset to the locatio...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/InModuleScope.ps1
InModuleScope.ps1
function InModuleScope { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string] $ModuleName, [Parameter(Mandatory = $true)] [scriptblock] $ScriptBlock ) if ($null -eq (Get-Variable -Name Pester -ValueOnly -ErrorAction SilentlyCont...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Mock.ps1
Mock.ps1
function Mock { <# .SYNOPSIS Mocks the behavior of an existing command with an alternate implementation. .DESCRIPTION This creates new behavior for any existing command within the scope of a Describe block. The function allows you to specify a ScriptBlock that will become the commands new behavior. O...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Describe.ps1
Describe.ps1
function Describe { <# .SYNOPSIS Defines the context bounds of a test. One may use this block to encapsulate a scenario for testing - a set of conditions assumed to be present and that should lead to various expected results represented by the IT blocks. .PARAMETER Name The name of the Test. This is often an...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Match.ps1
Match.ps1
function PesterMatch($value, $expectedMatch) { return ($value -match $expectedMatch) } function PesterMatchFailureMessage($value, $expectedMatch) { return "Expected: {$value} to match the expression {$expectedMatch}" } function NotPesterMatchFailureMessage($value, $expectedMatch) { return "Expe...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/MatchExactly.Tests.ps1
MatchExactly.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "MatchExactly" { It "returns true for things that match exactly" { PesterMatchExactly "foobar" "ob" | Should Be $true } It "returns false for things that do not match exactly" { PesterMatchExa...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/PesterThrow.Tests.ps1
PesterThrow.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "PesterThrow" { It "returns true if the statement throws an exception" { Test-PositiveAssertion (PesterThrow { throw }) } It "returns false if the statement does not throw an exception" { Test...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/BeNullOrEmpty.ps1
BeNullOrEmpty.ps1
function PesterBeNullOrEmpty($value) { if ($null -eq $value) { return $true } if ([String] -eq $value.GetType()) { return [String]::IsNullOrEmpty($value) } if ($null -ne $value.Count) { return $value.Count -lt 1 } return $false } function PesterBeNullO...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Should.Tests.ps1
Should.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "Parse-ShouldArgs" { It "sanitizes assertions functions" { $parsedArgs = Parse-ShouldArgs TestFunction $parsedArgs.AssertionMethod | Should Be PesterTestFunction } It "works with strict mode w...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Exist.ps1
Exist.ps1
function PesterExist($value) { return (Test-Path $value) } function PesterExistFailureMessage($value) { return "Expected: {$value} to exist" } function NotPesterExistFailureMessage($value) { return "Expected: ${value} to not exist, but it was found" }
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/PesterThrow.ps1
PesterThrow.ps1
$ActualExceptionMessage = "" $ActualExceptionWasThrown = $false # because this is a script block, the user will have to # wrap the code they want to assert on in { } function PesterThrow([scriptblock] $script, $expectedErrorMessage) { $Script:ActualExceptionMessage = "" $Script:ActualExceptionWasThrow...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/BeExactly.ps1
BeExactly.ps1
function PesterBeExactly($value, $expected) { return ($expected -ceq $value) } function PesterBeExactlyFailureMessage($value, $expected) { return "Expected: exactly {$expected}, But was {$value}" } function NotPesterBeExactlyFailureMessage($value, $expected) { return "Expected: value was {$valu...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/BeNullOrEmpty.Tests.ps1
BeNullOrEmpty.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "PesterBeNullOrEmpty" { It "should return true if null" { Test-PositiveAssertion (PesterBeNullOrEmpty $null) } It "should return true if empty string" { Test-PositiveAssertion (PesterBeNullOrE...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/MatchExactly.ps1
MatchExactly.ps1
function PesterMatchExactly($value, $expectedMatch) { return ($value -cmatch $expectedMatch) } function PesterMatchExactlyFailureMessage($value, $expectedMatch) { return "Expected: {$value} to exactly match the expression {$expectedMatch}" } function NotPesterMatchExactlyFailureMessage($value, $expe...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Match.Tests.ps1
Match.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "Match" { It "returns true for things that match" { PesterMatch "foobar" "ob" | Should Be $true } It "returns false for things that do not match" { PesterMatch "foobar" "slime" | Should Be $fa...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/BeExactly.Tests.ps1
BeExactly.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "BeExactly" { It "passes if letter case matches" { 'a' | Should BeExactly 'a' } It "fails if letter case doesn't match" { 'A' | Should Not BeExactly 'a' } It "passes for numbers" { 1 | Shou...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Be.ps1
Be.ps1
function PesterBe($value, $expected) { return ($expected -eq $value) } function PesterBeFailureMessage($value, $expected) { return "Expected: {$expected}, But was {$value}" } function NotPesterBeFailureMessage($value, $expected) { return "Expected: value was {$value}, but should not have been t...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Contain.Tests.ps1
Contain.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "PesterContain" { Context "when testing file contents" { Setup -File "test.txt" "this is line 1`nrush is awesome" It "returns true if the file contains the specified content" { Test-PositiveAsser...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Test-Assertion.ps1
Test-Assertion.ps1
function Test-PositiveAssertion($result) { if (-not $result) { throw "Expecting expression to pass, but it failed" } } function Test-NegativeAssertion($result) { if ($result) { throw "Expecting expression to pass, but it failed" } }
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Contain.ps1
Contain.ps1
function PesterContain($file, $contentExpecation) { return ((Get-Content $file) -match $contentExpecation) } function PesterContainFailureMessage($file, $contentExpecation) { return "Expected: file ${file} to contain {$contentExpecation}" } function NotPesterContainFailureMessage($file, $contentExpe...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Should.ps1
Should.ps1
function Parse-ShouldArgs([array] $shouldArgs) { if ($null -eq $shouldArgs) { $shouldArgs = @() } $parsedArgs = @{ PositiveAssertion = $true ExpectedValue = $null } $assertionMethodIndex = 0 $expectedValueIndex = 1 if ($shouldArgs.Count -gt 0 -and $shouldArgs[0]...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Exist.Tests.ps1
Exist.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "PesterExist" { It "returns true for paths that exist" { Test-PositiveAssertion (PesterExist $TestDrive) } It "returns false for paths do not exist" { Test-NegativeAssertion (PesterExist "$Tes...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/Be.Tests.ps1
Be.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "PesterBe" { It "returns true if the 2 arguments are equal" { Test-PositiveAssertion (PesterBe 1 1) } It "returns true if the 2 arguments are equal and have different case" { Test-PositiveAssertion...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/ContainExactly.Tests.ps1
ContainExactly.Tests.ps1
Set-StrictMode -Version Latest InModuleScope Pester { Describe "PesterContainExactly" { Context "when testing file contents" { Setup -File "test.txt" "this is line 1`nPester is awesome" It "returns true if the file contains the specified content exactly" { T...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/Functions/Assertions/ContainExactly.ps1
ContainExactly.ps1
function PesterContainExactly($file, $contentExpecation) { return ((Get-Content $file) -cmatch $contentExpecation) } function PesterContainExactlyFailureMessage($file, $contentExpecation) { return "Expected: file ${file} to contain exactly {$contentExpecation}" } function NotPesterContainExactlyFail...
PowerShellCorpus/Github/naeemkhedarun_Console/Third Party/Modules/Pester/ObjectAdaptations/PesterFailure.ps1
PesterFailure.ps1
Add-Type -language CSharp @' public class PesterFailure { public string Expected; public string Observed; public PesterFailure(string Expected,string Observed){ this.Expected = Expected; this.Observed = Observed; } public override string ToString(){ return string....