Skip to content

Instantly share code, notes, and snippets.

View TearTheSky's full-sized avatar

TearTheSky (Masumi Yoshida) TearTheSky

View GitHub Profile
@TearTheSky
TearTheSky / Create-Folder.ps1
Created April 12, 2013 09:21
カレントフォルダ以下のフォルダ名を引数に入れる。 存在すれば何もしない。 存在しなければその名前のフォルダを作る。
#フォルダの存在を確認して、無ければ作る関数
Function Create-Folder( $folderName ) {
if(Test-Path $folderName) {
}
else {
$currentDirectory = Get-Location
$createLocation = "$currentDirectory\$folderName"
New-Item -type directory $createLocation
}
}
@TearTheSky
TearTheSky / CheckFileExist.ps1
Created April 15, 2013 00:38
ファイル存在確認関数。ファイルが存在する場合はTrueを返す。ファイルが存在しない場合はメッセージを出力してfalseを返す。
#ファイル存在確認関数
Function CheckFileExist($fileName) {
$resultCheckFileExist = Test-Path $fileName
if($resultCheckFileExist -eq $false) {
#いない場合は怒って終了
Write-Host "ファイル名「$fileName」は存在しません。"
return $false
}
else {
return $true
@TearTheSky
TearTheSky / rename-kun.ps1
Created September 28, 2013 04:37
リネームの機会が何回かあったため、PowerShellでリネームツール作成に挑戦してみました。 フォルダ内のファイル名を一括で変換してくれるすごいやつになる予定です。
#======================================================================
# author : TearTheSky
# フォルダ内のファイル名を一括で変換してくれるすごいやつ(予定)
#======================================================================
#----------------------------------------------------------------------
# - - - フォルダ選択ダイアログの表示 - - -
#----------------------------------------------------------------------
#フォルダ選択ダイアログの表示
@TearTheSky
TearTheSky / CreateNewADUsers.ps1
Created November 21, 2013 06:44
架空の会社の情シスになってActive Directoryを管理しなきゃいけなくなったので、CSVに書かれたユーザを一括で登録するスクリプトを作りました。
import-module ActiveDirectory
$company = 'tearthesky.com'
$usersOU = 'CN=Users,DC=tearthesky,DC=com'
write-host "Drop New Users List(CSV File)"
$csvFilePath = read-host
$newUsers = import-csv $csvFilePath
foreach($aUser in $newusers){
@TearTheSky
TearTheSky / logFilesSearch.ps1
Last active August 29, 2015 14:00
テキストエディタでいう、「フォルダ内を検索」のようなもの
$searchKey = "keyword which you want to search"
$outFileName = "result.txt"
$Items = get-childitem
foreach($aItem in $Items) {
$aLog = get-content $aItem
$results = @($aLog | select-string $searchKey)
$results | out-file $outFileName -append
}
write-output ($counter.tostring() + "人目のユーザアカウントを作成します。よろしいですか?")
$yesNo = read-host "(y / n)"
while ($yesNo -eq 'y')
{
try{
$name = Read-Host '作成したい新規参入者のユーザ名を入力してください。'
$server = [adsi]"WinNT://$env:computername"
$user = $server.Create("User", "$name")
# トランスクリプト(ログ出力)の開始
$yourLogfilePrefix = 'ログファイルにつけたい名前'
try {
Stop-Transcript
}
catch{
Write-Output '既に実行されているトランスクリプトはありません。問題ありません。'
}
Start-Transcript -Path ( (split-path $MyInvocation.MyCommand.Path) + "\" + $yourLogfilePrefix + $tennant + "_" +(get-date -Format "yyyyMMddhhmmss") + ".log")
@TearTheSky
TearTheSky / BlackBoard.StorableColorTheme.ps1xml
Created May 7, 2014 06:08
個人用PowerShell_ISEのテーマ(カラースキーマ)
<?xml version="1.0" encoding="utf-16"?>
<StorableColorTheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Keys>
<string>ErrorForegroundColor</string>
<string>ErrorBackgroundColor</string>
<string>WarningForegroundColor</string>
<string>WarningBackgroundColor</string>
<string>VerboseForegroundColor</string>
<string>VerboseBackgroundColor</string>
<string>DebugForegroundColor</string>
#引数定義
Param (
[string]$pathName = "",
[int]$targetSheetNumber = -1,
[string]$targetCollumn = "",
[int]$targetRow = -1
)
#******************************************************************************
<!-- HTML内埋め込み -->
<style type="text/css">
<!--
#menu li {
position: relative;
float: left;
margin: 0;
padding: 5px;
width: 200px;