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 / 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 / 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
@guitarrapc
guitarrapc / New-ZipCompress.ps1
Created November 21, 2014 08:31
New-ZipCompress
function New-ZipCompress
{
[CmdletBinding(DefaultParameterSetName="safe")]
param(
[parameter(
mandatory,
position = 0,
valuefrompipeline,
valuefrompipelinebypropertyname)]
@guitarrapc
guitarrapc / New-OSUser.ps1
Last active August 29, 2015 14:10
PowerShell DSC Advent Calendar 2014 : Day 2 なぜ Configuration Management が必要なのか : http://tech.guitarrapc.com/entry/2014/12/02/062659 // Adding New User to WorkGroup Environment. https://github.com/guitarrapc/DSCSample/blob/master/PowerShellDSCAdventCalendar/2014/Day2_WhyConfiuguraitonMangementToolIsRequired/UserByScript.ps1
function New-OSUser
{
<#
.Synopsis
Create New user
.DESCRIPTION
User will create as you passed Credential.
.EXAMPLE
New-OSUser -Credential (Get-Credential) -Groups Administrators
# create new user with Group assigned Administrators
configuration UserAndGroup
{
param
(
[parameter(Mandatory = 1)]
[PSCredential[]]$credential,
[parameter(Mandatory = 0)]
[string]$Group = "Administrators"
)
@guitarrapc
guitarrapc / PowerShellStringEvaluation.ps1
Last active August 29, 2015 14:10
PowerShell のString評価の方法と罠
# PowerShell の String中への変数埋め込みってば罠だらけね!
# 例 に示す変数をString中に表示するには5つ方法がある
$hoge = @{hoge = "hoge"}
$fuga = "fuga"
#1. 直 (Property指定がだめ
"$hoge"
'$hoge'
"$hoge.hoge"
# Chef Recipe rule
[cookbook] 'Nae' do
[Key_name] "[key_value]"
[value_name] "[value_value]"
end
# Chef DSC call EnvironemtResource with : https://github.com/opscode-cookbooks/dsc
env 'editor' do
# Do you think is work? NO........
powershell_script "executionpolicy" do
code 'Set-ExecutionPolicy RemoteSigned'
not_if "(Get-ExecutionPolicy -Scope LocalMachine) -eq 'RemoteSiggned'"
end
powershell_script "smbsharelogs" do
code 'New-SMBShare logshare C:\logs'
not_if 'Get-SMBShare logshare'
end