Skip to content

Instantly share code, notes, and snippets.

View guitarrapc's full-sized avatar
:octocat:

Ikiru Yoshizaki guitarrapc

:octocat:
View GitHub Profile
@guitarrapc
guitarrapc / PipelineExecutionStyles.ps1
Created September 5, 2014 12:05
PowerShell Pipeline Programming Style sample
function PipelineExecuteOnEndProcessingStyle
{
param
(
[parameter(Position = 0, Mandatory = 1, ValueFrompipeline = 1, ValueFromPipelineByPropertyName = 1)]
[string]$hostaddress
)
begin{ $hostaddresses = @() }
process
{
@guitarrapc
guitarrapc / valentiaTypeSample.ps1
Last active August 29, 2015 14:06
valentia Type sample with C#
Add-Type -TypeDefinition @"
public enum ValentiaBranchPath
{
Application = 1,
Deploygroup = 2,
Download = 3,
Maintenance = 4,
Upload = 5,
Utils = 6
}
@guitarrapc
guitarrapc / ValentiaTypeSampleV5.ps1
Created September 7, 2014 22:02
Valentia TypeSample with PowerShell v5
Enum ValentiaBranchPath
{
Application = 1
Deploygroup = 2
Download = 3
Maintenance = 4
Upload = 5
Utils = 6
}
@guitarrapc
guitarrapc / PowershellConstructor.ps1
Last active August 29, 2015 14:06
PowerShell Class Constructor Sample
########################
# Constructor Call check
########################
class Hoge
{
Hoge()
{
Write-Host "constuctor called"
}
}
@guitarrapc
guitarrapc / PowerShellClassSamples.ps1
Last active August 29, 2015 14:06
PowerShell Class Samples
Class CopyItemClass
{
[string]$Path
[string]$Destination
[string]$Item
[PSObject] SetItem([string]$Path, [string]$Destination)
{
$result = copy-Item -Path $Path -Destination $Destination -PassThru
Write-Warning ("Item Copied from {0} to {1}" -f $Path, $Destination)
@guitarrapc
guitarrapc / PowerShellClassScopeCheck.ps1
Created September 7, 2014 23:13
PowerShell Class Scope is Lexical
$d = 42 # Script scope
function bar
{
$d = 0 # Function scope
[MyClass]::DoSomething()
}
class MyClass
{
# Present
configuration ACLChange
{
Import-DscResource -ModuleName GraniResource
node Localhost
{
File hoge
{
Ensure = "Present"
configuration present
{
Import-DscResource -Modulename GraniResource
Node $AllNodes.Where{$_.Role -eq "localhost"}.NodeName
{
cScheduleTask hoge
{
Ensure = "present"
Execute = "powershell.exe"
Argument = "-Command 'Get-Date | Out-File c:\hoge.log'"
configuration present
{
Import-DscResource -Modulename GraniResource
Node $AllNodes.Where{$_.Role -eq "localhost"}.NodeName
{
cScheduleTask hoge
{
Ensure = "present"
Execute = "powershell.exe"
Argument = "-Command 'Get-Date | Out-File c:\hoge.log'"
1..8 | % {$n="1" * $_; Write-Host ("{0,9} x {0,9} = " -f $n) -n;$x=("$n * $n" | iex); $x | %{$n=$_;$l=$_ -split "";[int]$z=($l.length-1)/2;$l | where {$_} | %{$i=1}{if($l.length -2 -eq 1){Write-Host $_ -Fo Red}elseif($i -eq $l.length - 2){Write-Host $_}elseif($i -eq $z){Write-Host $_ -n -Fo Red}elseif($i -lt $z){Write-Host $_ -n}elseif($i -gt $z){Write-Host $_ -n};$i++}}}