Home > database >  would like to extract words from a path - powershell
would like to extract words from a path - powershell

Time:08-11

I am running a script in which has a path like below

  • C:\Program Files\Atlassian\JIRA\logs\
  • C:\Program Files\Atlassian\Confluence\logs\
  • C:\Atlassian\ApplicationData\Bitbucket\log
  • C:\Atlassian\bitbucket-backup-client-4.0.0\backups\

and want to extract words display it like

  • Jira - Logs
    • list of files Not Deleted
    • list of files Deleted
  • Confluence - Logs
    • list of files Not Deleted
    • list of files Deleted
  • Bitbucket - Logs
    • list of files Not Deleted
    • list of files Deleted
  • Bitbucket - Backups
    • list of files Not Deleted
    • list of files Deleted
  • etc...

as it goes through various paths and does the work. I have the code for the not deleted files and deleted files...

just would like to capture earlier mentioned details and display it while it is doing the function.

part of PowerShell function where I am using and capturing log using start-transcript - path "log path"

    if ($files.count -gt 0)
    {
    Write-Host "List of Files not deleted"
        for ($i= ($files.Count - $keep); $i -lt $Files.Length; 
$i  )
        {
            #$Files[$i]
            Write-output $files[$i].fullname
        }
    if (($files.Count - $keep) -gt 0) 
            {
        # reduce the array to contain only the number of files in $keep
        $files = $files | Sort-Object LastWriteTime | Select-Object -First $keep
         Write-Output "------------------"
         Write-Output "List of Deleted Files from " 
         Write-output "------------------"
         Write-Output $files.FullName | format-table
         Write-output "------------------"
        #$date,"List of Files Deleted" $files.FullName | Add- Content -Path 'E:\backup\housekeep_log\Housekeep.log' #-verboes
        #$files | Remove-Item -Force
    }
    stop-transcript
    

CodePudding user response:

Another possibility would be:

$caption = $path.Parent.Name   " - "   $path.Name

CodePudding user response:

stored values in to a csv file...and called it through variable.

$config = Import-Csv -Path 'E:\Backup\Scripts\HousekeepConfig.csv'
 #Write-Output $Config
 $date = Get-Date  -Format "yyyMMdd_hhmmss"  
 Start-Transcript -Path E:\Backup\Housekeep_Log\Housekeep.log
  $oldpath = get-location
 foreach ($item in $config) 
  {
  Write-host $item.Name | Format-table
  • Related