I recently wrote a script that archives IIS logs into a remote server. The script runs by importing a module that mainly contains functions to copy, zip and remove files. I am populating the script the using a CSV File, which I have attached.
The cutoffdate in the CSV represents the retention period for the IISLogs.
I do not want to run the delete action if the copy action returns an error. So, I added a column name called ActionID and PreCheckForActionID.
Later, when the script runs, for every object, I plan to add a new column in the imported CSV called results.. Hence, Before a remove action takes place, I would like to check for the PreCheckForActionID , filter the Action associated with it and check it the action was a success or returned an error.
This is what I have so far and I am completely lost, since I do not know how to go about getting the ActionID related to the PreCheckForActionID object.
$Newlist = Import-Csv C:\powershell\Servers.csv | Add-Member -MemberType noteproperty -Name Results -Value "success" -PassThru | Select-Object ActionID, Action, ServerName, PreCheckForActionID, Results
$verynew = $Newlist | Select-Object -Property ActionID, Results, PreCheckForActionID | Select-Object -Property ActionID,PreCheckForActionID
foreach($item in $verynew)
{
$item.PreCheckForActionID
}
Here's how the CSV file looks like:
ActionID ServerName FileType Action Sourcefolder Destination Ext Compress CutOffPeriod PreCheckForActionID 1 A IISLogs Copy C$\Temp C:\Test\A\IISLogs .log N 2 B IISLogs Copy C$\TEMP C:\Test\B\IISLogs .log Y 3 C Backups Copy C$\Backup C:\Test\C\Backups .bak Y 4 A IISLogs Delete C$\Temp .log 15 1
Can someone help me out with the next step on how to correlate my PreCheckForActionID with an ActionID?