Skip to content

Instantly share code, notes, and snippets.

@chiita
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiita/b07e99937070fc2f2fe8 to your computer and use it in GitHub Desktop.
Save chiita/b07e99937070fc2f2fe8 to your computer and use it in GitHub Desktop.
######################################################
# PS名称: Microsoft.PowerShell_pfofile.ps1
# 概要: powershellの標準出力をファイルに取得
# 
# $PROFILE を編集
# PS実行時のディレクトリは C:\Users\Administrator
#
# 1.PSでの画面出力をファイルに取得
#
# 2.finファンクションにて、ログアウト時にコマンド履歴を
#   CSVで出力 → ログ取得を停止
#
# ※powershell終了時は fin を実行しログアウトすること
######################################################
# ==================== 変数定義 ==================== #
$YYYYMMDD=date -format yyyyMMdd
$LOG="E:\work\logs\PS_$YYYYMMDD.log"
$CSVPATH="C:\Users\Administrator\Documents\WindowsPowerShell\.pshistory.csv"
# ==================== 関数定義 ==================== #
# 標準出力のログ取得開始する関数
function startlog() {
start-transcript $LOG -append
}
# ログ取得停止の関数
function endlog() {
stop-transcript
}
# Powershellログアウト時に使用する関数
# 使用しないとコマンド実行履歴が取得できない
function fin() {
get-history | export-csv $CSVPATH
endlog
exit
}
# 単体実行だけではログ出力ができないコマンドの対応
function pin($1,$2) {
ping $1 $2 | out-default
}
function ifconfig($1) {
ipconfig $1 | out-default
}
# ==================== 処理開始 ==================== #
import-csv $CSVPATH | add-history
startlog
#バックグランドで実行
#start-job xxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment