Guest User

Untitled

a guest
Jun 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. @(echo '"') | Out-Null <# ") > NUL
  2. @ECHO OFF
  3. SETLOCAL ENABLEEXTENSIONS
  4. SET "p=%~dp0.%~nx0"
  5. SET f="%p%\.ps1"
  6. IF NOT EXIST %f% (
  7. MD "%p%" 2> NUL
  8. ATTRIB +H "%p%"
  9. MKLINK /H %f% "%~f0" > NUL
  10. )
  11. powershell -ex Unrestricted -nop -f %f% %*
  12. EXIT /B
  13.  
  14. このファイルを .ps1 ファイルとして PowerShell で実行
  15. #>
  16.  
  17. & {
  18. Param(
  19. [switch] $XML,
  20. [int] $Duration,
  21. [string] $WorkingDirectory
  22. )
  23.  
  24. # 管理者でなければ昇格
  25.  
  26. $c = [Security.Principal.WindowsIdentity]::GetCurrent()
  27. $p = [Security.Principal.WindowsPrincipal] $c
  28. $r = [Security.Principal.WindowsBuiltInRole]
  29. if (!($p.IsInRole($r::Administrator))) {
  30.  
  31. # UAC のダイアログに表示されるため引数を整理
  32.  
  33. $a = @()
  34. if ($XML) {
  35. $a += '-XML'
  36. }
  37. if ($Duration) {
  38. $a += '-Duration', $Duration
  39. }
  40. $a += '-WorkingDirectory'
  41. if ($WorkingDirectory) {
  42. $a += $WorkingDirectory
  43. } else {
  44. $a += gl
  45. }
  46.  
  47. saps powershell (
  48. '-ExecutionPolicy', 'Unrestricted', '-NoProfile',
  49. '-File' + $PSCommandPath + $a
  50. ) -Verb 'runas' -Wait
  51. break
  52. }
  53.  
  54. # 昇格後引き継がれないためディレクトリ変更
  55.  
  56. if ($WorkingDirectory) {
  57. sl $WorkingDirectory
  58. }
  59.  
  60. # 古い項目の移動
  61.  
  62. $c = 'old'
  63. $x = if ($XML) { '.xml' } else { '.html' }
  64.  
  65. 'battery-report', 'sleepstudy-report' | % {
  66. $f = "$_$x"
  67. if (Test-Path $f) {
  68. if (!(Test-Path $c -t c)) {
  69. md $c
  70. }
  71. $t = (gp $f).LastWriteTime.ToString('yyyy_MM_dd HH_mm_ss')
  72. mi $f "$c\$_ ($t)$x"
  73. }
  74. }
  75.  
  76. # レポートの作成
  77.  
  78. $a = @()
  79. if ($XML) {
  80. $a += '/XML'
  81. }
  82. if ($Duration) {
  83. $a += '/DURATION', $Duration
  84. }
  85.  
  86. '/BATTERYREPORT', '/SLEEPSTUDY' | % {
  87. powercfg $_ @a
  88. }
  89. } @args
Add Comment
Please, Sign In to add comment