質問編集履歴

6

修正

2019/10/01 04:22

投稿

zazabi
zazabi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -26,37 +26,49 @@
26
26
 
27
27
  ```PowerShell
28
28
 
29
+ # 対象ファイルのあるフォルダ
30
+
31
+ $search = "<対象フォルダパス>"
32
+
33
+
34
+
35
+ ## サービスの文字列の環境別個数ト(サービス名,教育,検証,ステージングと本番)
36
+
37
+ # 実際カウント数は $A0102,$Apache,$Shibboleth に格納
38
+
39
+ $word_1 = @("<文字列1>","a1","a2","a3")
40
+
41
+ $word_2 = @("<文字列2>","b1","b2","b3")
42
+
43
+ $word_3 = @("<文字列3>","c1","c2","c3")
44
+
45
+
46
+
29
47
  # 最終更新のファイルのフルパスを取得
30
48
 
31
49
  $path = (Get-ChildItem $search | Sort-Object LastWriteTime -Desc)[0].FullName
32
50
 
33
51
 
34
52
 
35
- # 検索文字列と正規文字列の個
53
+ # ファイル名に文字列が含まれるかどうか
36
54
 
37
- $service_1 = @("<文字列1>","a1","a2","a3")
55
+ function word ($a){$path.Contains($a)}
38
-
39
- $service_2 = @("<文字列2>","b1","b2","b3")
40
-
41
- $service_3 = @("<文字列3>","c1","c2","c3")
42
56
 
43
57
 
44
58
 
45
59
  # ファイル内の文字列を数える
46
60
 
47
- function count ($a,$b){
61
+ function count ($b,$c){
48
62
 
49
- (Select-String -Path $a -Pattern $b).Count
63
+ (Select-String -Path $b -Pattern $c).Count
50
64
 
51
65
  }
52
66
 
67
+ $x1 = (count $path $word_1[0])
53
68
 
69
+ $x2 = (count $path $word_2[0])
54
70
 
55
- $x1 = (count $path $service_1[0])
56
-
57
- $x2 = (count $path $service_2[0])
58
-
59
- $x3 = (count $path $service_3[0])
71
+ $x3 = (count $path $word_3[0])
60
72
 
61
73
 
62
74
 
@@ -66,35 +78,63 @@
66
78
 
67
79
  if($1 -eq $2 -and $3 -eq $4 -and $5 -eq $6){
68
80
 
69
- Write-Output ("一致しています。")
81
+ Write-Output ("件数が一致しています。")
70
82
 
71
- }else{
83
+ }else{
72
84
 
73
- Write-Output ("一致していません。")
85
+ Write-Output ("件数が一致していません。")
74
86
 
75
- }
87
+ }
76
88
 
77
89
  }
78
90
 
79
91
 
80
92
 
81
- if($path.Contains($service_1[0]) -eq "True"){
93
+ # 数えた結果を出力
82
94
 
83
- seisa $service_1[1] $x1 $service_1[2] $x2 $service_1[3] $x3
95
+ function message ($1,$2,$3,$4,$5,$6){
84
96
 
85
- }elseif($path.Contains($service_2[0]) -eq "True"){
97
+ Write-Output ($word_1[0]+""+$1+"/"+$2+"個あります。")
86
98
 
87
- seisa $service_2[1] $x1 $service_2[2] $x2 $service_2[3] $x3
99
+ Write-Output ($word_2[0]+"は"+$3+"/"+$4+"個あります。")
88
100
 
89
- }elseif($path.Contains($service_3[0]) -eq "True"){
101
+ Write-Output ($word_1+""+$5+"/"+$6+"個あります。")
90
102
 
103
+ }
104
+
105
+
106
+
107
+ if(word "ED1" -eq "True"){
108
+
109
+ seisa $word_1[1] $x1 $word_2[2] $x2 $word31[1] $x3
110
+
111
+ message $x1 $word_1[1] $x2 $word_2[1] $x3 $word_3[1]
112
+
113
+ }elseif(word "KT1" -eq "True"){
114
+
115
+ seisa $word_1[2] $x1 $word_2[3] $x2 $word_3[2] $x3
116
+
117
+ message $x1 $word_1[2] $x2 $word_2[2] $x3 $word_3[2]
118
+
119
+ }elseif(word "STA"] -eq "True"){
120
+
91
- seisa $service_3[1] $x1 $service_3[2] $x2 $service_3[3] $x3
121
+ seisa $word_1[1] $x1 $word_2[2] $x2 $word_3[3] $x3
122
+
123
+ message $x1 $word_1[3] $x2 $word_2[4] $x3 $word_3[3]
124
+
125
+ }elseif(word "HON" -eq "True"){
126
+
127
+ seisa $word_1[1] $x1 $word_2[2] $x2 $word_3[3] $x3
128
+
129
+ message $x1 $word_1[3] $x2 $word_2[4] $x3 $word_3[3]
92
130
 
93
131
  }Else{
94
132
 
95
- Write-Output ("ファイルが見つかりません。")
133
+ Write-Output ("ファイルが見つかりません。")
96
134
 
97
135
  }
136
+
137
+
98
138
 
99
139
  ```
100
140
 

5

修正

2019/10/01 04:22

投稿

zazabi
zazabi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -43,6 +43,14 @@
43
43
 
44
44
 
45
45
  # ファイル内の文字列を数える
46
+
47
+ function count ($a,$b){
48
+
49
+ (Select-String -Path $a -Pattern $b).Count
50
+
51
+ }
52
+
53
+
46
54
 
47
55
  $x1 = (count $path $service_1[0])
48
56
 

4

修正

2019/10/01 02:33

投稿

zazabi
zazabi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -72,15 +72,15 @@
72
72
 
73
73
  if($path.Contains($service_1[0]) -eq "True"){
74
74
 
75
- seisa $service_1[2] $x1 $service_1[3] $x2 $service_1[4] $x3
75
+ seisa $service_1[1] $x1 $service_1[2] $x2 $service_1[3] $x3
76
76
 
77
77
  }elseif($path.Contains($service_2[0]) -eq "True"){
78
78
 
79
- seisa $service_2[2] $x1 $service_2[3] $x2 $service_2[4] $x3
79
+ seisa $service_2[1] $x1 $service_2[2] $x2 $service_2[3] $x3
80
80
 
81
81
  }elseif($path.Contains($service_3[0]) -eq "True"){
82
82
 
83
- seisa $service_3[2] $x1 $service_3[3] $x2 $service_3[4] $x3
83
+ seisa $service_3[1] $x1 $service_3[2] $x2 $service_3[3] $x3
84
84
 
85
85
  }Else{
86
86
 

3

修正

2019/10/01 02:31

投稿

zazabi
zazabi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -64,6 +64,8 @@
64
64
 
65
65
  Write-Output ("一致していません。")
66
66
 
67
+ }
68
+
67
69
  }
68
70
 
69
71
 

2

指摘事項の修正

2019/10/01 02:27

投稿

zazabi
zazabi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -32,6 +32,16 @@
32
32
 
33
33
 
34
34
 
35
+ # 検索文字列と正規の文字列の個数
36
+
37
+ $service_1 = @("<文字列1>","a1","a2","a3")
38
+
39
+ $service_2 = @("<文字列2>","b1","b2","b3")
40
+
41
+ $service_3 = @("<文字列3>","c1","c2","c3")
42
+
43
+
44
+
35
45
  # ファイル内の文字列を数える
36
46
 
37
47
  $x1 = (count $path $service_1[0])
@@ -39,16 +49,6 @@
39
49
  $x2 = (count $path $service_2[0])
40
50
 
41
51
  $x3 = (count $path $service_3[0])
42
-
43
-
44
-
45
- # 検索文字列と正規の文字列の個数
46
-
47
- $service_1 = @("<文字列1>","a1","a2","a3")
48
-
49
- $service_2 = @("<文字列2>","b1","b2","b3")
50
-
51
- $service_3 = @("<文字列3>","c1","c2","c3")
52
52
 
53
53
 
54
54
 

1

タイトル修正

2019/10/01 02:02

投稿

zazabi
zazabi

スコア24

test CHANGED
@@ -1 +1 @@
1
- PowerShellで条件分岐させた後に条件で関数の変数を変えるコマンド
1
+ PowerShellで条件分岐させた後に関数の変数を変えるコマンド
test CHANGED
File without changes