All posts by Atle

Script to delete files older thans x days

This script will delete files older than 10 days.

$Now = Get-Date
$LastWrite = $Now.AddDays(-10)
$Files = get-childitem -Path “C:\folder_with_files_to_delete” |Where {$_.CreationTime -le $LastWrite}
foreach ($File in $Files)
{Remove-Item -Path $File -Force}

Save this script as “c:\scripts\deleteoldfiles.ps1”

In schedule task select program/script to run : “C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe”

and use : -command “c:\scripts\deleteoldfiles.ps1” as argument

Remember you has to set the execution policy to allow this script to run. (set-executionpolicy -executionpolicy remotesigned)

Update:

For PowerShell 1.0 and filter on file Attribute:

# Written by  Atle Vatland @ Cegal AS
# Remember to change path,attribute and fileextension.
# When tested OK – remove  WHATIF from Remove-item and the files will be deleted.
# Schedule a task.
# Save this script as “c:\scripts\filename.ps1”
# In schedule task select program/script to run : “C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe”
# and use : -command “c:\scripts\filename.ps1” as argument
# Remember you has to set the execution policy to allow this script to run. (set-executionpolicy -executionpolicy remotesigned)
 

$Now = Get-Date
$LastWrite = $Now.AddDays(-14)
$Files = get-childitem -Path “E:\filepath\*” -include *.ext |Where {$_.LastWriteTime -le $LastWrite}
$Today= ” ———================== Files deleted ” + $Now + “====================——————–”
$Today | Out-File -filepath c:\scripts\deletedfiles.log -Append
foreach ($File in $Files)

{
$FI=get-item $File
 if($FI.Attribute -notlike “*Archive*”){
  $File | ft -HideTableHeaders | out-file -filepath c:\scripts\deletedfiles.log -Append;remove-item $File -whatif
 }
}

Exchange Powershell Max Quota exceeded.

When doing some exchange powershell you would probably get this error or somthing like it sooner or later:

Connecting to remote server failed with the following error message : The WS-Management service cannot process the request. This user is allowed a max
imum number of 18 concurrent shells, which has been exceeded. Close existing shells or raise the quota for this user. For more information, see the about_Remote_Trouble
shooting Help topic.
    + CategoryInfo          : OpenError: (System.Manageme….RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionOpenFailed

Workaround for this is to recycle the MSExchangePowerShellAppPool Application Pool

Lync phone calls failes, and log reports/sniff that Lync server cancel it.

When calling some foreign numers Lync server CANCEL the call when it is in progress. Network sniff shows that the call is terminates after 10 sec.

 

This is a default value of the Lync Routing engine. The value is located in “c:\program files\Microsoft Lync Server 2010\Server\Core\OutboundRouting.exe.config”

SOLUTION:Replace value “FailOverTimeout” value 10000 with a value of 20000. Reboot server. Remember to do this on every frontend server that is involved. You will have to reboot involved servers for this to be activated

<configuration>
    <appSettings>
      <add key=”FailOverTimeout” value=”20000″/>
      <add key=”MinGwWaitingTime” value=”1″/>
      <add key=”MaxGwWaitingTime” value=”20″/>
      <add key=”FailuresForGatewayDown” value=”10″/>
      <add key=”FailuresForGatewayLessPreferred” value=”25″/>
      <!– Valid values are between 5 and 600 –>
      <add key=”HealthMonitoringInterval” value=”300″/>
      <!– Valid values are between 60 and 3600 –>
      <add key=”GatewayStateReportingInterval” value=”1800″ />
  </appSettings>
</configuration>

DPM 2012 backup Sharepoint 2010

To backup sharepoint from DPM 2012 you willl first have to install DPM agent. Then run %program files%\Microsoft Data Protection Manager\DPM\Bin\

ConfigureSharepoint.exe -EnableSharepointProtection

When asked fore WSSCmdletsWrapper user enter your farm administrator.

If you get an error : 

Then the user you have logged on to the server with does not have the right permissions on the SQL instance.

 

DPM 2012 system state backup failed with error 2033.

In some cases DPM agent installed and pointed to the wrong drive as temp drive.  You will get an error 2033 

“DPM encountered an error while performing an operation for F:\WindowsImageBackup\ on server.test.local (ID 2033 Details: The system cannot find the path specified (0x80070003))”

 This can be solved by editing DPM PSDatasourceconfig.xml file.  The “FilesToProtect” entry contains the incorrect value.

Ref: http://technet.microsoft.com/en-us/library/bb809015.aspx

Unable to create exchange test user using “new-TestCasConnectivityUser.ps1”

[PS] C:\Program Files\Microsoft\Exchange Server\V14\Scripts>.\new-TestCasConnectivityUser.ps1
Please enter a temporary secure password for creating test users. For security purposes, the password will be changed r
egularly and automatically by the system.
Enter password: **********************************
Create test user on: Server1.test.local
Click CTRL+Break to quit or click Enter to continue.:
CreateTestUser : Mailbox could not be created. Verify that OU ( Users ) exists and that password meets complexity requi
rements.
At C:\Program Files\Microsoft\Exchange Server\V14\Scripts\new-TestCasConnectivityUser.ps1:267 char:31
+       $result = CreateTestUser <<<<  $exchangeServer $mailboxServer $securePassword $OrganizationalUnit $UMDialPlan $
UMExtension $Prompt
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CreateTestUser

This error is because you have several OU’s named “Users”. Edit the scrip to use a spesific OU, i.e “CN=Users,DC=test,DC=local”

Collection of Tools

Microsoft iSCSI Target 3.3 http://www.microsoft.com/download/en/details.aspx?id=19867

Sysinternals http://technet.microsoft.com/en-us/sysinternals/default.aspx

Remote Desktop Connection Manager http://www.microsoft.com/download/en/details.aspx?id=21101

NetMon parsers http://nmparsers.codeplex.com/releases/view/79102

LyncParser for NetMon http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=22440

Network Monitor 3.4 http://www.microsoft.com/download/en/details.aspx?id=4865

NBLookup Netbios/wins test http://support.microsoft.com/kb/830578

Paint.NET http://www.getpaint.net/download.html

Lync Server 2010 SDK http://www.microsoft.com/en-us/download/confirmation.aspx?id=19675

ImgBurn http://www.imgburn.com

IIS Transform Manager 1.0 http://www.microsoft.com/en-us/download/details.aspx?id=29889&WT.mc_id=rss_alldownloads_all

Magic ISO http://www.magiciso.com/tutorials/miso-magicdisc-history.htm

Microsoft Screen recorder http://technet.microsoft.com/en-ca/magazine/2009.03.utilityspotlight2.aspx

Sysloggersmall http://sourceforge.net/projects/sysloggersmall/?source=directory