I had a request recently to provide an inactive user report for the past 60 days. Basically, find out which accounts have not logged in for the past 60 days so action can be taken against them. The request was for a multi domain forest which queries every domain controller and gets the latest lastlogon…
Tag: days
No remote Desktop License Server available on RD Session Host server 2012 R2
A fully functional and activated 2012 R2 Remote Desktop Session Host server displayed the following message: This was a simple setup on one server with the: connection broker, Session Host and Licensing server with 2012 R2 CAL’s installed. Even though the licensing seems to be configured correctly, in server manager: and PowerShell: Licensing diagnostics: everywhere…
Delete Files and Folders Older Than X Days
Often times admin have to creates tasks like removing log files or some other files on a regular schedule. Here is an automated way of removing files / folders older than X days. Create a Batch file or Powershell script and add it to scheduled task. Batch File:
1 2 3 4 5 6 7 8 9 10 11 12 |
@echo off :: set folder path set dump_path=c:\shares\dump :: set min age of files and folders to delete set max_days=7 :: remove files from %dump_path% forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd /c del /q @path" :: remove sub directories from %dump_path% forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path" |
Powershell:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# set folder path $dump_path = "C:\shares\dump" # set min age of files $max_days = "-7" # get the current date $curr_date = Get-Date # determine how far back we go based on current date $del_date = $curr_date.AddDays($max_days) # delete the files Get-ChildItem $dump_path -Recurse | Where-Object { $_.LastWriteTime -lt $del_date } | Remove-Item |
Extending the Booking days for Conference Room Calendar (Resource)
By default Office365 limits Resource booking days to just 180 days. The maximum days it can be booked for 1080 days. I like to make resource booking days 1 year from the day of making the reservation/ appointment. Now instead of visiting each calendar and making the change, powershell can help us out.
1 2 3 4 5 6 7 8 9 |
#Connect to Office365 $cred = Get-Credential Import-Module MSOnline Connect-MsolService -Credential $cred $s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection $importresults = Import-PSSession $s #Get all the Rooms and make the booking days to 365 Get-MailBox | Where {$_.ResourceType -eq "Room"} | Set-CalendarProcessing -BookingWindowInDays 365 |
Happy…