Làm việc với HTML trong PowerShell



lệnh ghép ngắn

New-Item cmdlet được sử dụng để tạo một tệp html và Set-Content cmdlet để đưa nội dung vào đó

Show

Bước 1

Trong ví dụ này, chúng tôi đang tạo một tệp html mới có tên test. html

Nhập lệnh sau trong Bảng điều khiển PowerShell ISE

New-Item D:\temp\test\test.html -ItemType File

Bạn có thể xem bài kiểm tra. html được tạo trong D. thư mục \temp\test

Bước 2

Trong ví dụ này, chúng tôi đang thêm nội dung để kiểm tra. html

Nhập lệnh sau trong Bảng điều khiển PowerShell ISE

Set-Content D:\temp\test\test.html 'Welcome to TutorialsPoint'

Bước 3

Trong ví dụ này, chúng tôi đang đọc nội dung của bài kiểm tra. html

Get-Content D:\temp\test\test.html

đầu ra

Bạn có thể thấy đầu ra sau trong bảng điều khiển PowerShell

Welcome to TutorialsPoint

PowerShell là một công cụ mạnh mẽ giúp bạn đơn giản hóa và tự động hóa các tác vụ tẻ nhạt và lặp đi lặp lại. Quản trị viên thường sử dụng PowerShell để trích xuất thông tin từ hệ thống hoặc cơ sở dữ liệu khi tập dữ liệu được yêu cầu phải được trình bày dưới dạng báo cáo. Tuy nhiên, các báo cáo ở dạng văn bản hoặc tệp CSV thường thiếu kiểu dáng đẹp mắt và nổi bật của HTML. Trong hướng dẫn này, bạn sẽ tìm hiểu cách tạo Báo cáo HTML nn bằng PowerShell,

Không phải là một độc giả?

Không nhìn thấy video?

PowerShell có thể giúp bạn tạo báo cáo HTML và tránh xa các định dạng nhạt nhẽo khác này. Chỉ sử dụng PowerShell, bạn có thể làm cho báo cáo trở nên sống động với HTML cho phép bạn tạo bản trình bày có ý nghĩa về dữ liệu thô được trích xuất từ ​​hệ thống. Bạn thậm chí có thể áp dụng Cascading Style Sheets (CSS) để dễ dàng tùy chỉnh bố cục báo cáo của mình

Trong bài viết này, bạn sẽ học cách sử dụng lệnh ghép ngắn

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
6 kết hợp với lệnh ghép ngắn
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
7 để tạo báo cáo HTML. Bạn cũng sẽ học tập lệnh cơ bản cho CSS và cách nó có thể hữu ích trong việc định dạng thiết kế báo cáo dựa trên HTML của bạn

điều kiện tiên quyết

Bài viết này sẽ là một hướng dẫn. Nếu bạn có ý định làm theo, hãy đảm bảo rằng bạn đã thiết lập trước các điều kiện tiên quyết sau

  • Tất cả các ví dụ sẽ được hiển thị bằng Windows 10 Build 1709, nhưng phiên bản này không bắt buộc
  • Windows PowerShell 5. 1 hoặc phiên bản mới hơn của PowerShell Core 7
  • Trình duyệt như Internet Explorer hoặc Google Chrome

Tạo Báo cáo Thông tin Máy tính Cơ bản bằng cách sử dụng Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html8

Để trình bày cách sử dụng lệnh ghép ngắn

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8 và các tham số của nó, bạn sẽ tạo một tập lệnh lấy thông tin cơ bản của máy (chẳng hạn như Hệ điều hành, Bộ xử lý, BIOS và dung lượng đĩa khả dụng) và tạo thông tin cho báo cáo HTML

Bạn bắt đầu với một lệnh thu thập thông tin về phiên bản hệ điều hành từ một máy. Mở bảng điều khiển PowerShell của bạn, sau đó sao chép và dán lệnh bên dưới rồi nhấn enter để chạy lệnh

________số 8_______

Khi bạn chạy lệnh trên, lệnh ghép ngắn

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
0 sẽ thu thập các thuộc tính của lớp
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
1 chứa thông tin về hệ điều hành của máy, lệnh sẽ trả về nhiều kết quả, do đó cần lọc để chỉ lấy các thông tin liên quan. Kết quả sẽ trông giống như ảnh chụp màn hình hiển thị bên dưới

Làm việc với HTML trong PowerShell
Thông tin hệ điều hành của máy

Bây giờ bạn đã có lệnh trả về thông tin hệ điều hành, hãy chuyển đổi kết quả thành mã HTML. Để chuyển đổi kết quả (đối tượng) từ lệnh trên sang mã HTML, bạn có thể chuyển đầu ra của lệnh ghép ngắn

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
0 thành
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8. Chạy lệnh bên dưới trong bảng điều khiển PowerShell của bạn

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html

Bạn có thể thấy trong ảnh chụp màn hình bên dưới rằng PowerShell tự động tạo các thẻ HTML từ đầu ra của lệnh ghép ngắn

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
0. Kết quả được hiển thị ở định dạng bảng, trong đó tiêu đề bảng hiển thị các tên thuộc tính như Phiên bản, Chú thích, Số bản dựng và Nhà sản xuất. Mỗi hàng của bảng đại diện cho một đối tượng và hiển thị các giá trị của đối tượng cho từng thuộc tính

Làm việc với HTML trong PowerShell
Mã HTML được tạo

Xuất báo cáo thành tệp HTML

Bây giờ bạn đã có kết quả và được chuyển đổi thành mã HTML, hãy xuất báo cáo sang tệp HTML bằng cách sử dụng lệnh ghép ngắn

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
5 và xem báo cáo trong trình duyệt web. Đưa đầu ra của lệnh ghép ngắn
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8 và chỉ định đường dẫn mà bạn muốn lưu báo cáo bằng cách sử dụng tham số
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
7 và sử dụng Basic-Computer-Information-Report. html làm tên của tệp

Mở PowerShell ISE của bạn hoặc bất kỳ trình soạn thảo văn bản nào, sao chép mã bên dưới và lưu tập lệnh với tên tệp Generate-HTML-Report. Ps1

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html

Chạy Tạo-HTML-Báo cáo. Tập lệnh Ps1 trong Bảng điều khiển PowerShell của bạn

.\Generate-HTML-Report.Ps1

Sau khi chạy tập lệnh, hãy mở Basic-Computer-Information-Report. tệp html trong trình duyệt web. Trình duyệt web diễn giải mã của báo cáo HTML và hiển thị dữ liệu trên màn hình trình duyệt. Báo cáo phải chứa thông tin về hệ điều hành của máy tương tự như ảnh chụp màn hình bên dưới

Làm việc với HTML trong PowerShell
Báo cáo HTML được xem trong trình duyệt web

Kết hợp Báo cáo Sử dụng Tham số Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html8

Lúc này, bạn đã có một đoạn script lấy thông tin về hệ điều hành của máy và xuất kết quả sang báo cáo HTML. Mục tiêu của bạn là thêm nhiều lệnh hơn trong tập lệnh để lấy thông tin còn lại của máy tính như Bộ xử lý, BIOS, Đĩa và Dịch vụ

Mỗi lệnh sẽ trả về thông tin máy tính khác nhau được định dạng là mã HTML. Để hợp nhất đúng thông tin trong một báo cáo HTML, hãy sử dụng tham số

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
8 để chỉ lấy phần bảng của mã HTML được tạo bởi lệnh ghép ngắn
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8

Như bạn có thể thấy trong ảnh chụp màn hình bên dưới, PowerShell tạo tất cả các phần tử HTML cơ bản khi đầu ra được dẫn đến lệnh ghép ngắn

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8

Làm việc với HTML trong PowerShell
Danh sách mã HTML được tạo bằng cách sử dụng lệnh ghép ngắn
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8

Khi bạn sử dụng tham số

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
8, PowerShell chỉ tạo phần tử bảng HTML. Các phần tử
.\Generate-HTML-Report.Ps1
4,
.\Generate-HTML-Report.Ps1
5,
.\Generate-HTML-Report.Ps1
6,
.\Generate-HTML-Report.Ps1
7 và các phần tử khác được lược bỏ. Kết quả sẽ được hiển thị dưới đây

Làm việc với HTML trong PowerShell
Danh sách mã HTML cho bảng sử dụng tham số Fragment

Bây giờ bạn đã biết cách tham số

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
8 hoạt động từ ví dụ trên, hãy áp dụng điều đó trong tập lệnh

Các lệnh trong tập lệnh bên dưới thực hiện như sau

  • Năm dòng lệnh đầu tiên lấy thông tin khác nhau từ máy như Hệ điều hành, Bộ xử lý, BIOS, Đĩa và Dịch vụ
  • Lọc kết quả bằng cách sử dụng tham số
    .\Generate-HTML-Report.Ps1
    9 để chỉ hiển thị các giá trị có liên quan
  • Lưu trữ các giá trị trong các biến tương ứng. Mỗi thông tin được định dạng dưới dạng bảng sử dụng
    #The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
    $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment
    
    #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
    $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment
    
    #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
    $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment
    
    #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
    $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment
    
    #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
    $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
     
    #The command below will combine all the information gathered into a single HTML report
    $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 
    
    #The command below will generate the report to an HTML file
    $Report | Out-File .\Basic-Computer-Information-Report.html
    0
  • Hợp nhất các bảng HTML bằng cách sử dụng tham số
    #The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
    $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment
    
    #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
    $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment
    
    #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
    $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment
    
    #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
    $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment
    
    #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
    $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
     
    #The command below will combine all the information gathered into a single HTML report
    $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 
    
    #The command below will generate the report to an HTML file
    $Report | Out-File .\Basic-Computer-Information-Report.html
    1 thành một báo cáo HTML
  • Đặt tiêu đề của báo cáo thành “Computer Information Report” sử dụng tham số
    #The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
    $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment
    
    #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
    $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment
    
    #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
    $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment
    
    #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
    $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment
    
    #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
    $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
     
    #The command below will combine all the information gathered into a single HTML report
    $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 
    
    #The command below will generate the report to an HTML file
    $Report | Out-File .\Basic-Computer-Information-Report.html
    2
  • Xuất báo cáo dưới dạng tệp HTML sử dụng tham số
    Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
    5

Thông tin bổ sung về tập lệnh có sẵn trong các nhận xét trong đoạn mã bên dưới. Cập nhật tập lệnh với đoạn mã sau

#The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment

#The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
 
#The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 

#The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html

Chạy tập lệnh trong bảng điều khiển PowerShell. Bạn có thể thấy đầu ra của báo cáo như hình dưới đây

Làm việc với HTML trong PowerShell
Báo cáo HTML với thông tin máy tính cơ bản

Thêm Nhãn Sử dụng Tham số #The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html4 và #The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html5

Tại thời điểm này, tập lệnh hiện có thể lấy tất cả thông tin cơ bản của máy tính và xuất kết quả sang HTML. Tuy nhiên, như bạn có thể thấy trong ảnh chụp màn hình ở trên, ai đó hoặc người nhận báo cáo có thể gặp khó khăn trong việc hiểu nội dung khi bạn xóa chú thích vì thông tin không được gắn nhãn hoặc phân loại đúng cách

Bằng cách sử dụng các tham số

#The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment

#The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
 
#The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 

#The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html
4 và
#The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment

#The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
 
#The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 

#The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html
5, bạn có thể thêm nhãn vào mỗi bảng để mọi người có thể dễ dàng phân biệt nội dung của báo cáo

Tham số

#The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment

#The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
 
#The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 

#The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html
4 chỉ định văn bản cần thêm trước thẻ mở
#The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment

#The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
 
#The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 

#The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html
9 và tham số
#The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment

#The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
 
#The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 

#The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html
5 chỉ định văn bản sẽ thêm sau thẻ đóng
#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

1. Các giá trị được thêm vào trên các tham số này không được tự động chuyển đổi thành mã Html, vì vậy bạn cần sử dụng các thẻ HTML một cách rõ ràng để nó được hiển thị chính xác dưới dạng phần tử HTML

Cập nhật tập lệnh bằng các lệnh bên dưới, sau đó chạy tập lệnh trong bảng điều khiển PowerShell

Dưới đây là những thay đổi trong tập lệnh

  • Lệnh mới được thêm vào để lấy tên của máy tính. Giá trị của biến
    #The command below will get the name of the computer
    $ComputerName = "

    Computer name: $env:computername

    " #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

    Operating System Information

    " #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

    Processor Information

    " #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

    BIOS Information

    " #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

    Disk Information

    " #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

    Services Information

    " #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

    Creation Date: $(Get-Date)

    " #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

    2 có thẻ
    #The command below will get the name of the computer
    $ComputerName = "

    Computer name: $env:computername

    " #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

    Operating System Information

    " #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

    Processor Information

    " #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

    BIOS Information

    " #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

    Disk Information

    " #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

    Services Information

    " #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

    Creation Date: $(Get-Date)

    " #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

    3 để thay đổi định dạng văn bản thành tiêu đề khi hiển thị trên trình duyệt
  • Các nhãn khác nhau được thêm vào trong mỗi bảng bằng cách sử dụng
    #The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
    $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment
    
    #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
    $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment
    
    #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
    $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment
    
    #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
    $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment
    
    #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
    $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
     
    #The command below will combine all the information gathered into a single HTML report
    $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 
    
    #The command below will generate the report to an HTML file
    $Report | Out-File .\Basic-Computer-Information-Report.html
    4 Thông số và giá trị được đặt trong thẻ
    #The command below will get the name of the computer
    $ComputerName = "

    Computer name: $env:computername

    " #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

    Operating System Information

    " #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

    Processor Information

    " #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

    BIOS Information

    " #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

    Disk Information

    " #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

    Services Information

    " #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

    Creation Date: $(Get-Date)

    " #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

    5
  • Nhãn ngày tạo được thêm vào cuối báo cáo bằng cách sử dụng
    #The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
    $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment
    
    #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
    $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment
    
    #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
    $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment
    
    #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
    $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment
    
    #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
    $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
     
    #The command below will combine all the information gathered into a single HTML report
    $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 
    
    #The command below will generate the report to an HTML file
    $Report | Out-File .\Basic-Computer-Information-Report.html
    5 Tham số và giá trị được đặt trong thẻ
    #The command below will get the name of the computer
    $ComputerName = "

    Computer name: $env:computername

    " #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

    Operating System Information

    " #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

    Processor Information

    " #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

    BIOS Information

    " #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

    Disk Information

    " #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

    Services Information

    " #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

    Creation Date: $(Get-Date)

    " #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

    7

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

Bạn có thể thấy với một chút công việc bổ sung, báo cáo có thể trông đẹp hơn rất nhiều, báo cáo sẽ được cập nhật như hình bên dưới

Làm việc với HTML trong PowerShell
Báo cáo HTML được thêm nhãn bằng Tham số PreContent và PostContent

Thay đổi bố cục bảng bằng tham số #The command below will get the name of the computer $ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html8

Có thể, bảng HTML được tạo có nhiều cột và bạn muốn thay đổi định dạng để hiển thị đúng giá trị dưới dạng danh sách, bạn có thể sử dụng tham số

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

8. Theo mặc định, khi bạn chuyển đầu ra thành
#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

0, PowerShell sẽ tạo một bảng HTML giống với định dạng bảng Windows PowerShell

Như bạn có thể thấy trong ảnh chụp màn hình bên dưới, tiêu đề bảng hiển thị các tên thuộc tính như Phiên bản, Chú thích, Số bản dựng và Nhà sản xuất và mỗi hàng của bảng đại diện cho một đối tượng và hiển thị các giá trị của đối tượng cho từng thuộc tính

Làm việc với HTML trong PowerShell
Mã HTML được tạo bởi lệnh ghép ngắn ConvertTo-Html được định dạng dưới dạng Bảng

Để thay đổi bố cục của bảng thành danh sách, hãy sử dụng tham số

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

1 sau đó là Danh sách. PowerShell tạo bảng HTML hai cột cho từng đối tượng giống với định dạng danh sách Windows PowerShell. Cột đầu tiên hiển thị tên thuộc tính như Phiên bản, Chú thích, Số bản dựng và Nhà sản xuất và cột thứ hai hiển thị giá trị thuộc tính

Làm việc với HTML trong PowerShell
Mã HTML được tạo bởi lệnh ghép ngắn ConvertTo-Html được định dạng dưới dạng Danh sách

Từ các ví dụ trên, bây giờ bạn đã có ý tưởng về cách thay đổi bố cục của bảng, hãy áp dụng tham số

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

8 trong tập lệnh của chúng ta để thay đổi bố cục của bảng thông tin Hệ điều hành, Bộ xử lý, BIOS và Đĩa sang định dạng danh sách

Cập nhật tập lệnh với đoạn mã sau bên dưới. Tập lệnh có tham số

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

1 trong các dòng lệnh cho Hệ điều hành, Bộ xử lý, BIOS và Đĩa

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

Sau khi áp dụng tham số

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

1, báo cáo sẽ được cập nhật như hình bên dưới. Bố cục bảng cho thông tin Hệ điều hành, Bộ xử lý, BIOS và Đĩa hiện được thay đổi thành danh sách

Làm việc với HTML trong PowerShell
Báo cáo HTML với các bảng được định dạng là Danh sách

Nâng cao Báo cáo bằng CSS

Hãy đưa báo cáo lên cấp độ tiếp theo và bắt đầu thêm thiết kế bằng CSS. CSS được sử dụng để kiểm soát cách báo cáo HTML sẽ trông như thế nào trong trình duyệt web. CSS kiểm soát phông chữ, văn bản, màu sắc, hình nền, lề và bố cục. Ở cuối phần này, bạn sẽ có thể xem cách báo cáo sẽ chuyển đổi từ định dạng đơn giản sang định dạng phong phú bằng cách sử dụng CSS

Có ba cách để áp dụng CSS trong HTML như Inline, Internal và External. Đối với bài viết này, bạn sẽ áp dụng phương thức Internal sử dụng tham số

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

5 trong báo cáo HTML

Tham số

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

5 chỉ định nội dung của thẻ
.\Generate-HTML-Report.Ps1
5. Thẻ
.\Generate-HTML-Report.Ps1
5 là một phần của cấu trúc HTML nơi bạn đặt mã cho CSS. Như bạn có thể thấy trong ảnh chụp màn hình bên dưới, thẻ
#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

9 đã được bao gồm khi mã HTML được tạo bởi lệnh ghép ngắn
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8

Làm việc với HTML trong PowerShell
Mã HTML hiển thị phần tử Head

Bây giờ hãy sử dụng CSS để định dạng báo cáo HTML. Đầu tiên, sao chép mã bên dưới và dán vào đầu tập lệnh. Mã CSS được gán trong biến

$header = @"


@”
1 sẽ thay đổi định dạng của văn bản trong báo cáo được đặt trong thẻ
#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

3

$header = @"


@”

Tiếp theo, sử dụng tham số

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

5 và gán biến
$header = @"


@”
1. Cập nhật tập lệnh bằng mã bên dưới

$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

Khi bạn chạy tập lệnh, báo cáo sẽ được cập nhật như hình bên dưới. Lưu ý rằng phần tử HTML bị ảnh hưởng duy nhất là

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

3 được áp dụng cho nhãn "Tên máy tính". Các bước trên là một ví dụ tuyệt vời về cách bạn có thể kiểm soát hoặc điều khiển thiết kế của báo cáo HTML bằng CSS

Làm việc với HTML trong PowerShell
Báo cáo HTML với CSS sử dụng Tham số Head

Để thêm nhiều thiết kế hơn cho các bảng và nhãn khác được đặt trong thẻ

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

5 trong báo cáo, hãy tiếp tục cập nhật biến
$header = @"


@”
1 bằng mã CSS bên dưới

$header = @"

"@

Sau khi cập nhật và chạy tập lệnh, báo cáo sẽ được định dạng như hình bên dưới – Nhờ có CSS, báo cáo giờ đây trông bắt mắt và trông chuyên nghiệp

Làm việc với HTML trong PowerShell
Báo cáo HTML được định dạng bằng CSS

Sử dụng HTML Id và thuộc tính lớp trong CSS

Các phần tử HTML là các khối xây dựng của toàn bộ báo cáo HTML của bạn, CSS sử dụng các phần tử này làm công cụ chọn để biết nên áp dụng kiểu ở đâu. Từ các ví dụ trước, mã CSS đã được áp dụng cho các phần tử HTML

$header = @"


@”
8,
$header = @"


@”
9 và
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

0 trong báo cáo. Nhưng nếu bạn cần áp dụng phong cách khác nhau trên các yếu tố khác nhau thì sao? . Khi thiết kế báo cáo HTML của mình, bạn có thể sử dụng id hoặc lớp để xác định một phần tử

Xin lưu ý rằng một phần tử HTML chỉ có thể có một id duy nhất thuộc về phần tử đó, trong khi tên lớp có thể được sử dụng bởi nhiều phần tử. Đối với các nhà phát triển web, các thuộc tính này không chỉ để thiết kế trang mà chủ yếu được sử dụng trong tập lệnh để xử lý cách trang sẽ phản hồi mọi sự kiện hoặc yêu cầu

Hãy áp dụng các thuộc tính id và class trong báo cáo HTML. Như bạn có thể thấy trong đoạn mã bên dưới, nhãn ngày tạo được đặt trong thẻ

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

7

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
0

Khi báo cáo được tạo và xem trong trình duyệt, nhãn ngày tạo được định dạng như hình bên dưới

Làm việc với HTML trong PowerShell
Báo cáo HTML hiển thị nhãn ngày tạo

Để định dạng nhãn ngày tạo bằng thuộc tính id – Đầu tiên, gán tên id ‘CreationDate‘ cho thẻ

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

7. Tên id nên được đặt bên trong thẻ bắt đầu. Mã cập nhật được hiển thị bên dưới

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
1

Thứ hai, tạo mã CSS mới để định dạng nhãn ngày tạo. Sử dụng ký hiệu

$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

3 theo sau là tên ID khi khai báo ID trong CSS. Thêm mã CSS bên dưới vào biến
$header = @"


@”
1 rồi lưu và chạy tập lệnh trong bảng điều khiển PowerShell

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
2

Sau khi chỉ định id và tạo mã CSS mới nhắm mục tiêu thuộc tính id của thẻ

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable $OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "

Operating System Information

" #The command below will get the Processor information, convert the result to HTML code as table and store it to a variable $ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "

Processor Information

" #The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable $BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "

BIOS Information

" #The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable $DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "

Disk Information

" #The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable $ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "

Services Information

" #The command below will combine all the information gathered into a single HTML report $Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "

Creation Date: $(Get-Date)

" #The command below will generate the report to an HTML file $Report | Out-File .\Basic-Computer-Information-Report.html

7, báo cáo sẽ được cập nhật như hình bên dưới

Làm việc với HTML trong PowerShell
Báo cáo HTML hiển thị nhãn ngày tạo được định dạng bằng CSS qua ID làm bộ chọn

Hãy áp dụng thuộc tính lớp trong bảng thông tin Dịch vụ. Sử dụng CSS thay đổi màu của văn bản thành màu xanh lá cây ** khi giá trị của trạng thái Đang chạy và sử dụng màu đỏ khi giá trị là Đã dừng

Làm việc với HTML trong PowerShell
Báo cáo HTML hiển thị bảng Thông tin dịch vụ

Như đã đề cập trước đó, các thuộc tính lớp có thể được gán cho nhiều phần tử HTML. Trong báo cáo HTML, phần tử chứa văn bản Đang chạy và Đã dừng là thẻ

$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

6. Sử dụng phương thức
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

7 của PowerShell, gán tên lớp RunningStatus và StopStatus cho tất cả các thẻ
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

6 trong bảng thông tin Dịch vụ. Sử dụng các lệnh bên dưới và cập nhật tập lệnh

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
3

Add the following CSS code below in the

$header = @"


@”
1 variable. All
tags with a class name of RunningStatus will have the hexadecimal value of
$header = @"

"@
0  which is equivalent to color green,  and All
tags with a class name of StopStatus will have the hexadecimal value of
$header = @"

"@
1  which is equivalent to color red.

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
4

Lưu và chạy tập lệnh. Bảng thông tin Dịch vụ trong báo cáo cần được cập nhật như hình bên dưới

Làm việc với HTML trong PowerShell
Báo cáo HTML hiển thị bảng Thông tin dịch vụ được định dạng bằng CSS thông qua bộ chọn lớp

Dưới đây là bố cục cuối cùng của báo cáo HTML được định dạng bằng CSS

Làm việc với HTML trong PowerShell
Bố cục cuối cùng của báo cáo HTML

Dưới đây là các lệnh hoàn chỉnh cho Tạo-HTML-Báo cáo. Ps1

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
5

Phần kết luận

Trong bài viết này, bạn đã học cách chuyển đổi các đối tượng (kết quả) thành mã HTML và tạo chúng thành báo cáo HTML

Tạo báo cáo sang định dạng HTML cung cấp cho bạn khả năng áp dụng CSS giúp báo cáo dễ dàng cải thiện và thao tác hơn. Có rất nhiều tài nguyên trực tuyến miễn phí mà bạn có thể sử dụng để nâng cao kỹ năng thiết kế CSS và viết mã HTML của mình.

Tôi hy vọng bài viết này cung cấp cho bạn đủ ý tưởng về cách bạn có thể tạo và cải thiện báo cáo HTML của mình. Chúc mừng

Đọc thêm

  • Chuyển đổi sang Html
  • Thu thập thông tin về máy tính
  • HTML và CSS

Ghét quảng cáo?

Khám phá sách hướng dẫn ATA

Thông tin khác từ ATA Learning & Partners

  • Làm việc với HTML trong PowerShell

    Tài nguyên được đề xuất

    Tài nguyên được đề xuất cho đào tạo, bảo mật thông tin, tự động hóa, v.v.

  • Làm việc với HTML trong PowerShell

    Được trả tiền để viết

    ATA Learning luôn tìm kiếm những người hướng dẫn ở mọi cấp độ kinh nghiệm. Bất kể bạn là quản trị viên cấp dưới hay kiến ​​trúc sư hệ thống, bạn đều có điều gì đó để chia sẻ. Tại sao không viết trên một nền tảng có khán giả hiện có và chia sẻ kiến ​​thức của bạn với mọi người?

  • Làm việc với HTML trong PowerShell

    Sách hướng dẫn học tập ATA

    ATA Learning được biết đến với các hướng dẫn bằng văn bản chất lượng cao dưới dạng các bài đăng trên blog. Hỗ trợ Học tập ATA với sách điện tử PDF Sách hướng dẫn ATA khả dụng ngoại tuyến và không có quảng cáo

    Làm cách nào để sử dụng HTML trong PowerShell?

    New-Item cmdlet được sử dụng để tạo một tệp html và Set-Content cmdlet để đưa nội dung vào đó. .
    Trong ví dụ này, chúng tôi đang tạo một tệp html mới có tên test. html. .
    Trong ví dụ này, chúng tôi đang thêm nội dung để kiểm tra. .
    Trong ví dụ này, chúng tôi đang đọc nội dung của bài kiểm tra

    Làm cách nào để đọc HTML trong PowerShell?

    Lệnh ghép ngắn Get-Content được sử dụng để đọc nội dung của tệp html.

    Làm cách nào để tạo HTML bằng PowerShell?

    Cách tạo báo cáo HTML bằng PowerShell .
    Xuất báo cáo thành tệp HTML
    Kết hợp các báo cáo bằng cách sử dụng tham số phân đoạn
    Thêm nhãn bằng thông số PreContent và PostContent
    Thay đổi bố cục bảng bằng cách sử dụng làm tham số
    Nâng cao Báo cáo bằng CSS
    Sử dụng HTML Id và thuộc tính lớp trong CSS

    PowerShell có thể tương tác với các trang web không?

    PowerShell và Nội dung Web. PowerShell có một số cách để lấy dữ liệu từ một nguồn trên web, có thể là trang web bình thường hoặc API REST. Có sẵn hai lệnh ghép ngắn để thực hiện các yêu cầu web và PowerShell tất nhiên cũng có quyền truy cập vào mọi thứ .