こんにちは。
Get-SmbShare
で共有フォルダのパスは取得できますので、それに対してGet-ChildItem
を実行すればサブフォルダを取得できます。
例)
powershell
1Get-SmbShare -Special:$false | ForEach-Object {
2 # 共有フォルダのパスは Path プロパティで取れる
3 Write-Output ("共有フォルダ : {0}" -f $_.Path)
4
5 # Get-ChildItem を使ってサブフォルダの取得する
6 $subFolders = Get-ChildItem -LiteralPath $_.Path -Directory
7 foreach ($folder in $subFolders) {
8 # それぞれのサブフォルダ名の列挙
9 # ちなみにフルパスは FullName プロパティで取得できる
10 Write-Output ("サブフォルダ : {0}" -f $folder.Name)
11 }
12}
コメント欄のやり取りを反映して新しい例を追加しています。
例2) Test-Pathを追記
powershell
1Get-SmbShare -Special:$false | ForEach-Object {
2 # 共有フォルダのパスは Path プロパティ
3 Write-Output ("共有フォルダ : {0}" -f $_.Path)
4
5 # Get-ChildItem のまえにパスのチェックを実施
6 if (Test-Path -LiteralPath $_.Path -PathType Container) {
7 # Get-ChildItemを使ってサブフォルダの取得
8 $subFolders = Get-ChildItem -LiteralPath $_.Path -Directory
9 foreach ($folder in $subFolders) {
10 Write-Output ("サブフォルダ : {0}" -f $folder.Name)
11 }
12 }
13}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/23 05:19
2018/02/23 05:47
2018/02/23 06:48
2018/02/23 07:49
2018/02/23 08:28
2018/02/23 08:47
2018/02/23 09:01
2018/02/23 09:08
2018/02/27 02:35
2018/02/27 03:53
2018/02/27 05:52