Need help with a script that moves IIS logs.

I am trying to finish a script which migrates existing IIS Logs to a new folder structure. The server has less than 50 sites hosted on it. The folder path of the existing is W3SVC** where ** is the ID of the website. I have a hash table that looks up the ID of the website and corresponds it to the project name. Essentially at the end I would like to run this and all of the logs are moved to their new respective folder at: C:InetpubLogs<foldernameofenvironment><foldernameofproject>.

Here’s what I have so far. It creates a new folder called hashtable something or other and then moved the logs in there. I need it to be like: C:InetpubLogsQACustomerOrders.

As far as the environment variable and the project name variable, I do have a way to pull those in, in another script so treat them as just a static variable here.

$SiteID = @{ “1” = “Product1”;
“2” = “Product2”;
“3” = “Product3”;
“4” = “Product4”; }

$Logs = Get-ChildItem -Path “C:inetpublogsLogFiles”

$NewLogs = “C:Inetpublogs$SiteID.Values”

foreach ($log in $logs) {

$NewLogs = “C:Inetpublogs$SiteID.Values”

If(!(Test-Path $NewLogs)) { New-Item -ItemType Directory -Force -Path "C:Inetpublogs$NewLogs" } Else { Copy-Item "C:InetpublogsLogfiles*" $NewLogs -Recurse -Force | Rename-Item -NewName $SiteID.Values } } 

submitted by /u/Bluemoo25
[link] [comments]

Leave a Reply