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 / 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
# Configuraion sample
Configuration WebServer
{
WindowsFeature IIS
{
Ensure = "Present"
Name = "Web-Server"
IncludeAllSubFeature = $false
LogPath = "C:\Logs\DSC\WindowsFeature\Web-Server.txt"
@guitarrapc
guitarrapc / ConfiguraionServiceSample.ps1
Created December 6, 2014 21:13
PowerShell DSC Advent Calendar 2014 : Day 6 Configuration の記述 http://tech.guitarrapc.com/entry/2014/12/06/230000
Configuration Service
{
Service WinRM
{
Name = "WinRM"
State = "Running"
StartupType = "Automatic"
}
Service Winmgmt
@guitarrapc
guitarrapc / ConfigurationUserAndGroupSample.ps1
Last active August 29, 2015 14:10
PowerShell DSC Advent Calendar 2014 : Day 6 Configuration の記述 http://tech.guitarrapc.com/entry/2014/12/06/230000
Configuration Remote
{
param
(
[Parameter(Mandatory = 1, Position = 0)]
[pscredential]$Credential
)
User Remote
{
@guitarrapc
guitarrapc / ConfigurationServiceSampleWithForeach.ps1
Created December 6, 2014 22:20
PowerShell DSC Advent Calendar 2014 : Day 6 Configuration の記述 http://tech.guitarrapc.com/entry/2014/12/06/230000
Configuration Service
{
$service = "WinRM", "Winmgmt"
$state = "Running"
$startupType = "Automatic"
foreach ($x in $service)
{
Service $x
{