Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @(echo '"') | Out-Null <# ") > NUL
- @ECHO OFF
- SETLOCAL ENABLEEXTENSIONS
- SET "p=%~dp0.%~nx0"
- SET f="%p%\.ps1"
- IF NOT EXIST %f% (
- MD "%p%" 2> NUL
- ATTRIB +H "%p%"
- MKLINK /H %f% "%~f0" > NUL
- )
- powershell -ex Unrestricted -nop -f %f% %*
- EXIT /B
- このファイルを .ps1 ファイルとして PowerShell で実行
- #>
- & {
- Param(
- [switch] $XML,
- [int] $Duration,
- [string] $WorkingDirectory
- )
- # 管理者でなければ昇格
- $c = [Security.Principal.WindowsIdentity]::GetCurrent()
- $p = [Security.Principal.WindowsPrincipal] $c
- $r = [Security.Principal.WindowsBuiltInRole]
- if (!($p.IsInRole($r::Administrator))) {
- # UAC のダイアログに表示されるため引数を整理
- $a = @()
- if ($XML) {
- $a += '-XML'
- }
- if ($Duration) {
- $a += '-Duration', $Duration
- }
- $a += '-WorkingDirectory'
- if ($WorkingDirectory) {
- $a += $WorkingDirectory
- } else {
- $a += gl
- }
- saps powershell (
- '-ExecutionPolicy', 'Unrestricted', '-NoProfile',
- '-File' + $PSCommandPath + $a
- ) -Verb 'runas' -Wait
- break
- }
- # 昇格後引き継がれないためディレクトリ変更
- if ($WorkingDirectory) {
- sl $WorkingDirectory
- }
- # 古い項目の移動
- $c = 'old'
- $x = if ($XML) { '.xml' } else { '.html' }
- 'battery-report', 'sleepstudy-report' | % {
- $f = "$_$x"
- if (Test-Path $f) {
- if (!(Test-Path $c -t c)) {
- md $c
- }
- $t = (gp $f).LastWriteTime.ToString('yyyy_MM_dd HH_mm_ss')
- mi $f "$c\$_ ($t)$x"
- }
- }
- # レポートの作成
- $a = @()
- if ($XML) {
- $a += '/XML'
- }
- if ($Duration) {
- $a += '/DURATION', $Duration
- }
- '/BATTERYREPORT', '/SLEEPSTUDY' | % {
- powercfg $_ @a
- }
- } @args
Add Comment
Please, Sign In to add comment