Apoc70/Purge-LogFiles

Windows Server 2016

GeoHolz opened this issue · 4 comments

With WS 2016 and Exchange 2016 i have this issue :

[PS] C:\Windows\system32>C:\Script\ClearLogs-Apoc070.ps1 -DaysToKeep 20
Import-Module : The specified module 'GlobalFunctions' was not loaded because no valid module file was found in any
module directory.
At C:\Script\ClearLogs-Apoc070.ps1:139 char:1
+ Import-Module -Name GlobalFunctions
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (GlobalFunctions:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

New-Logger : The term 'New-Logger' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Script\ClearLogs-Apoc070.ps1:142 char:11
+ $logger = New-Logger -ScriptRoot $ScriptDir -ScriptName $ScriptName - ...
+           ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-Logger:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

You cannot call a method on a null-valued expression.
At C:\Script\ClearLogs-Apoc070.ps1:143 char:1
+ $logger.Write('Script started')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Removing IIS and Exchange logs - Keeping last 20 days - Be patient, it might take some time
You cannot call a method on a null-valued expression.
At C:\Script\ClearLogs.ps1:360 char:5
+     $logger.Write(('Purge-LogFiles started, keeping last {0} days of  ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Script\ClearLogs-Apoc070.ps1:373 char:5
+     $logger.WriteEventLog(('Script started. Script will purge log fil ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The folder \\TNS-MAIL-2016\D$\IISLogs doesn't exist or is not accessible! Check the folder path!
The folder \\TNS-MAIL-2016\E$\Program Files\Microsoft\Exchange Server\V15\Logging doesn't exist or is not accessible! Check the folder path!
You cannot call a method on a null-valued expression.
At C:\Script\ClearLogs-Apoc070.ps1:418 char:5
+     $logger.Write('Script finished')
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

0

The GlobalFunctions.psm1 PowerShell module is not installed on your server. This requirement is mentioned in the comment section of the script.

When running Windows Server 2016 you can easily install the module using
Install-Module GlobalFunctions
This assumes that your server does have internet connectivity.

My blog post describes the manual process for installing the GlobalFunctions module in more detail.

Thanks ! maybe add requirements in README of github ?

Now i have another bug :

Get-ChildItem : Access is denied
At C:\Script\ClearLogs.ps1:255 char:16
+ ...    $Files = Get-ChildItem -Path $TargetServerFolder -Include $Include ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetChildItemCommand

Ok. readme will be updated.

The access denied is not a bug. Your account does not have administrative rights to access the servers file system using administrative shares. Is the account in the local adminstrators group on all Exchange servers?

Yes. When i try to delete one manually it says :
The action can't be completed because file is open in Microsoft Exchange Mailbox-Assistants