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 / 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++}}}
@guitarrapc
guitarrapc / redis-server.sh
Last active August 29, 2015 14:07
Redis init.d Script for Redis 2.8.14. usage : sudo /etc/init.d/redis-server start | status | stop | restart
#!/bin/sh
# script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
function Get-FileHashIndex
{
<#
.Synopsis
Get File Hash for PowerShell V3 and Higher
.DESCRIPTION
Bringed C# how we retrieve File Hash to PowerShell Script.
This works equivalent to Get-FileHash (v4) but twice as faster and supports -Recurse switch.
measure-Command {Get-FileHashIndex -Path d:\test\test -Algorithm MACTripleDES -Recurse} # 684.4821
measure-Command {Get-FileHashIndex -Path d:\test\test -Algorithm MD5 -Recurse} # 631.5687
@guitarrapc
guitarrapc / WebPlatformInstaller.ps1
Last active June 15, 2016 22:40
PowerShell WebPlatformInstaller Module (rough)
#region Initializer
function New-WebPlatformInstaller
{
[OutputType([Void])]
[CmdletBinding()]
param()
try
{
@guitarrapc
guitarrapc / Remove-Office365LisenceFromUser.ps1
Created November 13, 2014 16:31
Remove Office365 User License
function Remove-Office365LicenseFromUser
{
[CmdletBinding()]
param
(
[Parameter(Position = 0, Mandatory = 1, HelpMessage = "Pass MsolUser Objects.")]
[Microsoft.Online.Administration.User[]]$users
)
configuration FixRemediateDriverIssue
{
# DSC GraniResource : https://github.com/guitarrapc/DSCResources/tree/master/Custom
Import-DscResource -ModuleName GraniResource
cScheduleTask PlugAndPlayCleanup
{
Ensure = "Present"
TaskName = 'Plug and Play Cleanup'
TaskPath = '\Microsoft\Windows\Plug and Play\'
Disable = $true