Ứng dụng:
Mở nhanh báo cáo: Tự động bật các link các report, Dashboard quan trọng để xem ngay số liệu đầu ngày.
Kiểm tra hệ thống (Health Check): Truy cập hàng loạt link quản trị để rà soát nhanh xem có lỗi hay bất thường gì không.
Điểm danh (Daily Check-in): Tự động truy cập các web AI hoặc dịch vụ có chế độ điểm danh nhận credit hàng ngày.
Duy trì trạng thái: Giữ cho tài khoản luôn ở trạng thái hoạt động (Active) trên các hệ thống yêu cầu tương tác thường xuyên.
1. Tạo các profile Chrome: Thiết lập các tài khoản riêng biệt để lưu session đăng nhập.
2. Lấy các Profile path: Xác định đường dẫn thư mục User Data của Chrome trên máy bạn
3. Chuẩn bị file excel : Quản lý danh sách link tập trung trong bảng tính.
Mỗi cột tương ứng với một khung giờ hoặc một Profile cụ thể :
Ví dụ:
• 7h sáng cần truy cập các link tại cột B, tại profile Default
• 7h30 sáng cần truy cập các link tại cột c, tại profile Default
4. Tạo script Powershell, copy đoạn code dưới vào notepad, sau đó lưu dưới đuôi PS1, để đọc dữ liệu từ Excel và điều khiển Chrome mở đúng Profile.
Sửa lại những phần highlight đỏ cho đúng thực tế.
Mở powershell lên và test code, cho đến khi chạy suôn sẻ rồi hãy lưu.
Lưu ý: Chỉ cần thay đổi số cột ($columnC) và tên Profile ($chromeProfileName) trong script cho mỗi lần tạo Task mới.
# Them dong nay vao dau script de dam bao cac kieu COM Interop duoc tai
Add-Type -AssemblyName 'System.Runtime.InteropServices'
# --- CAU HINH ---
$filePath = "D:\onedrive2\OneDrive\PUNGKOOK BK\EXCEL FILE\active_E5_project.xlsx" #Đây là path file excel. Hãy hỉnh sửa path theo thực tế
$fileName = Split-Path $filePath -Leaf
$sheetIndex = 1
$columnC = 2 #Số 2 là cột B, đổi số này để tương ứng với cột
$startRow = 2 # Số 2 là bắt đầu từ dòng 2, do dòng 1 là title.
$xlUp = -4162
# --- CAU HINH HO SO CHROME ---
$chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
$userDataDir = "C:\Users\PKUser\AppData\Local\Google\Chrome\User Data"
$chromeProfileName = "Default" #đây là chrome profile name
#Hãy hỉnh sửa path theo thực tế
# --- 1. KHOI TAO VA KIEM TRA EXCEL ---
$excelWasNew = $false
try {
# Su dung [System.Runtime.InteropServices.Marshal] sau khi da Add-Type o tren
$excel = [System.Runtime.InteropServices.Marshal]::GetActiveObject('Excel.Application')
} catch {
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $false
$excelWasNew = $true
}
# --- 2. MO WORKBOOK VA CHON SHEET ---
$workbook = $excel.Workbooks | Where-Object { $_.Name -eq $fileName }
$fileWasOpenedByScript = ($workbook -eq $null)
if ($fileWasOpenedByScript) {
$workbook = $excel.Workbooks.Open($filePath)
}
# --- 3. VONG LAP DOC DU LIEU VA MO LINKS ---
$sheet = $workbook.Sheets.Item($sheetIndex)
$linkCount = 0
# Tim dong cuoi cung
$endRow = $sheet.Cells.Item($sheet.Rows.Count, $columnC).End($xlUp).Row
$finalRow = [System.Math]::Max($endRow, $startRow)
for ($i = $startRow; $i -le $finalRow; $i++) {
$link = [string]$sheet.Cells.Item($i, $columnC).Text.Trim()
if ($link.Length -gt 0) {
$linkCount++
# SU DUNG START-PROCESS DE GOI CHROME (Toi uu hon Invoke-Expression)
# Su dung Start-Process hoac & truc tiep la cach an toan va nhanh hon
Start-Process -FilePath $chromePath `
-ArgumentList "--user-data-dir=`"$userDataDir`"", "--profile-directory=`"$chromeProfileName`"", "--new-tab", "`"$link`""
}
}
# --- 4. DON DEP VA THOAT EXCEL ---
if ($fileWasOpenedByScript) {
$workbook.Close($false)
}
if ($excelWasNew) {
$excel.Quit()
}
# Giai phong cac doi tuong COM
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($sheet) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($workbook) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($excel) | Out-Null
Remove-Variable -Name sheet, workbook, excel -ErrorAction SilentlyContinue
"Da mo tong cong $linkCount links tu file Excel su dung Ho so $chromeProfileName."
Script trên hoạt động như sau:
Đọc dữ liệu: Truy cập vào Sheet 1 của file Excel theo đường dẫn dc cung cấp.
Lọc danh sách: Quét toàn bộ link tại Cột B (tương ứng với $columnC = 2) bắt đầu từ dòng 2.
Kích hoạt trình duyệt: Gọi Chrome mở đúng Profile Default và tự động truy cập vào tất cả các link vừa tìm thấy dưới dạng các Tab mới.
5. Schedule task
Tạo task với lịch như mong muốn, tại phần Action, diền như sau:
Action: Start a program
Program: Powershell.exe
Arguments: -ExecutionPolicy Bypass -File "D:\onedrive2\OneDrive\PUNGKOOK BK\Temporately digital assessment\open_web_0.ps1"
=>đổi phần text đỏ bằng đường dẫn tới file script.
Nhận xét
Đăng nhận xét