function Show-FileMenu { while ($true) { Clear-Host Write-Host "===== Xscript v1.0 =====" -ForegroundColor Green Write-Host "===== Main Menu =====" -ForegroundColor Cyan Write-Host "[1] Enable certain 365 Credentials" # Write-Host "[2] Disable all 365 Credentials" Write-Host "[2] Clear 365 Credentials" Write-Host "[3] Backup 365 Credentials(only accounts files)" Write-Host "[4] Backup 365 Credentials(all files)" Write-Host "[5] Open 365 Credentials" Write-Host "[0] Exit" Write-Host "===== End =====" $choice = Read-Host "Select an option" switch ($choice) { "1" { } "2" { } "3" { Clear-Host $folderReady = Create-OfficeCredentialFolder if ($folderReady) { Backup-OfficeCredential } else { Write-Host "[STOP] Backup cancelled because backup folder is unavailable..." -ForegroundColor Red Write-Host "[MANUAL] Try create office-credentials at Documents Path manually..." -ForegroundColor Cyan } Read-Host "Press Enter to return to Main Menu" } "4" { Clear-Host $folderReadyBackup = Create-OfficeCredentialFolder if ($folderReadyBackup) { backup-AllCredential }else { Write-Host "[STOP] Backup cancelled because backup folder is unavailable..." -ForegroundColor Red Write-Host "[MANUAL] Try create office-credentials at Documents Path manually..." -ForegroundColor Cyan } Read-Host "Press Enter to return to Main Menu" } "5" { explorer.exe "$env:LOCALAPPDATA\Microsoft\OneAuth\accounts" } "0" { Write-Host "Goodbye!" -ForegroundColor Green return } default { Write-Host "Invalid option" -ForegroundColor Red Start-Sleep -Seconds 1 } } } } # For create folder function Create-OfficeCredentialFolder { $createFolder = "~\Documents\office-credentials" $checkPath = Test-Path "~\Documents\office-credentials" -PathType Container #check folder if($checkPath) { Write-Host "[SUCCESS] Folder exists..." -ForegroundColor Green # Write-Output (Resolve-Path $createFolder) Write-Host "[Location] $(Resolve-Path $createFolder)" -ForegroundColor Cyan return $true } else { Write-Host "[ERROR] Folder does not exists..." -ForegroundColor Red Write-Host "Started create folder..." -ForegroundColor Cyan # create folder without display info New-Item $createFolder -ItemType Directory | Out-Null $checkPath = Test-Path $createFolder -PathType Container if($checkPath) { Write-Host "[SUCCESS] Create folder..." -ForegroundColor Green # show full path # Write-Output (Resolve-Path $createFolder) Write-Host "[Location] $(Resolve-Path $createFolder)" -ForegroundColor Cyan return $true }else { Write-Host "[ERROR] Create folder failed..." -ForegroundColor Yellow Write-Host "[ERROR] Try to run with administration" -ForegroundColor Red return $false } } } #for backup function function backup-OfficeCredential { $backupRoot = "~\Documents\office-credentials" $backupLocation = "~\Documents\office-credentials" $checkCredential = Test-Path "$env:LOCALAPPDATA\Microsoft\OneAuth\accounts\" -PathType Container $credentialFolder = "$env:LOCALAPPDATA\Microsoft\OneAuth\accounts\" $credentialLocation = "$env:LOCALAPPDATA\Microsoft\OneAuth\accounts\*" #check folder if ($checkCredential) { #check folder inside have files if(Get-ChildItem -Path $credentialFolder -File -Recurse){ #create sub folder $dateTime = Get-Date -Format "yyyy-MM-dd_HHmmss" $backupLocation = Join-Path $backupRoot $dateTime New-Item -Path $backupLocation -ItemType Directory | Out-Null Write-Host "[START] Copy your credentials..." -ForegroundColor Yellow Copy-Item $credentialLocation $backupLocation -Recurse Write-Host "[END] Successfully copy your credentials..." -ForegroundColor Green }else { Write-Host "[ERROR] Folder inside does not have any files..." -ForegroundColor Red } } else { Write-Host "[ERROR] Folder does not exists..." -ForegroundColor Red } } function backup-AllCredential { $backupRoot = "~\Documents\office-credentials" $backupLocation = "~\Documents\office-credentials" $sourceFolders = @( "$env:LOCALAPPDATA\Microsoft\OneAuth" "$env:LOCALAPPDATA\Microsoft\IdentityCache" ) #create sub folder $dateTime = Get-Date -Format "yyyy-MM-dd_HHmmss" $backupLocation = Join-Path $backupRoot $dateTime New-Item -Path $backupLocation -ItemType Directory | Out-Null foreach ($folder in $sourceFolders) { if (Test-Path $folder -PathType Container) { Write-Host "[COPY] $folder" -ForegroundColor Cyan Copy-Item -Path $folder -Destination $backupLocation -Recurse }else { Write-Host "[ERROR] Try to run with administration..." -ForegroundColor Red } } Write-Host "[END] Successfully copy your credentials..." -ForegroundColor Green } Show-FileMenu