DFS отчет в формате HTML на PowerShell
Небольшой скрипт, для формирование удобно отчета по текущим DFS ссылкам в формате HTML со строкой поиска по TargetFolder. Скрипт можно зашарить на внутренний портал, для удобства в понимание окружающим.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
$AllDfs = Get-DfsnRoot $BodyHtml = ' <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * { box-sizing: border-box; } #myInput { background-position: 10px 10px; background-repeat: no-repeat; width: 100%; font-size: 16px; padding: 12px 20px 12px 40px; border: 1px solid #ddd; margin-bottom: 12px; } #myTable { border-collapse: collapse; width: 100%; border: 1px solid #ddd; font-size: 18px; } #myTable th, #myTable td { text-align: left; padding: 12px; } #myTable tr { border-bottom: 1px solid #ddd; } #myTable tr.header, #myTable tr:hover { background-color: #f1f1f1; } </style> </head> <body> <h2>DFS Spaces</h2> <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for Target folder.." title="Type in a target folder"> <table id="myTable"> <tr class="header"> <th style="width:20%;">Spaces</th> <th style="width:30%;">Spaces folder</th> <th style="width:30%;">Target folder</th> <th style="width:10%;">Status Folder</th> </tr>' foreach ($CurrentDfs in $AllDfs){ $DFSRoot = $CurrentDfs $DFSrootPath = $DFSRoot.path Write-Host 'Пространство' $DFSRoot.path -ForegroundColor Green -BackgroundColor Red ForEach-Object { $DFSFolder = Get-DfsnFolder -Path ($DFSRoot.path + "\*") foreach ($DFSFolder1 in $DFSFolder){ $DFSFOLPATH = $DFSFolder1.path Write-Host `t'Имя папки' $DFSFolder1.path -ForegroundColor Yellow -BackgroundColor Red $DFSTargetfolder = Get-DfsnFolderTarget $DFSFolder1.path foreach ($DFSTargetfolder1 in $DFSTargetfolder){ $DFSTARGT = $DFSTargetfolder1.TargetPath $TargetFolderStatus = $DFSTargetfolder1.State Write-Host `t`t'Конечная ссылка папки' $DFSTargetfolder1.TargetPath -ForegroundColor Black -BackgroundColor Red $arr += @( New-Object PSObject -Property @{DFSRootPath = "$DFSrootPath"; DFSRootFolder = "$DFSFOLPATH"; TargetFolder = "$DFSTARGT"; TargetFolderStatus = "$TargetFolderStatus"} ) if($DFSTargetfolder1.State -match "Online") { Write-Host `t`t`t'Ссылка включена' -ForegroundColor Yellow -BackgroundColor Green }else{Write-Host `t`t`t'Ссылка отключена' -ForegroundColor Yellow -BackgroundColor red} } }}} $BodyHtml3 = '</table> <script> function myFunction() { var input, filter, table, tr, td, i; input = document.getElementById("myInput"); filter = input.value.toUpperCase(); table = document.getElementById("myTable"); tr = table.getElementsByTagName("tr"); for (i = 0; i < tr.length; i++) { td = tr[i].getElementsByTagName("td")[2]; if (td) { if (td.innerHTML.toUpperCase().indexOf(filter) > -1) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } } </script> </body> </html> ' foreach ($arr1 in $arr){ $BodyHtml4 += "<tr><td>"+ $arr1.DFSRootPath +"</td>" $BodyHtml4 += "<td>"+ $arr1.DFSRootFolder +"</td>" $BodyHtml4 += "<td>"+ $arr1.TargetFolder +"</td>" $BodyHtml4 += "<td>"+ $arr1.TargetFolderStatus +"</td></tr>" } $totalBody = $BodyHtml + $BodyHtml4 + $BodyHtml3 $totalBody > c:\temp\dfs_link.html |