Author Posts

November 12, 2013 at 11:42 pm

i am writing to log files like this :

Function LogWrite
{
   Param ([string]$str,[bool]$bPrintDate=$true);
   if ($bPrintDate -eq $false) {
    Add-content $global:LogPathName -Encoding Unicode -value $str;
   }
   else {
       	$now=Get-Date;
    	$str=[string]::concat($now,"`t",$str);
       	Add-content $global:LogPathName -Encoding Unicode -value $str;
	}
}

and getting error :

Add-Content : The process cannot access the file 'D:\Logs\AD-AddUserManagers\20131113.log' because it is being used by
another process.

i don't see reason for this, i don't have multiple process that write to the same log file?

November 13, 2013 at 12:14 am

this happens when i run the script from the second time in the same powershell window.

November 13, 2013 at 2:33 am

solved, i had email attachemnt in function that need the dispose method and locked the file