Delete Files Older Than X Days with ForFiles Command
You can quickly delete files older than X days with ForFiles Command. Follow the given steps below to use CMD delete files older than x days:
Step 1. Left-click the Windows main menu and search for Command Prompt. Right-click the result and select the "Run as administrator" option.
Step 2. Type in ForFiles /p "C:\path\to\folder" /s /d -X /c "cmd /c del /q @file" to delete files on Windows that haven't been modified in the last X days and press Enter. In the command, change "C:\path\to\folder" specifying the path to the folder you want to delete files and change /d -X to select files with a last modified date.
ForFiles command breakdown
/p - indicates the pathname to start searching.
/s - instructs ForFiles to search inside subdirectories.
/d -specifies the last modified date for a file.
/c - instructs ForFiles to execute the command (must be wrapped in double quotes). The default is "cmd /c del @file".
/q -allows deleting folders without requiring confirmation.
It is possible to have 3 states when it comes to OneDrive files.
- Always available
- Locally available
- Online-only
See this link for full details: Set Files On-Demand states in Windows - SharePoint in Microsoft 365 | Microsoft Learn
I'm backing up some files that would fill up the C drive so each time I backup a file I unpin it. My OneDrive can hold 5TB so now I can keep lots more data when unpinned.
This is an example of how to unpin locally and save space. This is excellent in batch files for multiple files/folders.
attrib +u "C:\Users\[username]\OneDrive - [Company Name]\[FolderName]\*.*"
This can also be accomplished by using the right click menu in Windows Explorer.
This is how to get the Max ID and the Row Count for all tables in a SQL Database. It's a good way to check that things look OK!
The MaxValues should not be wildly, more than the row count unless you know that rows have been deleted constantly, like the use of a temp table for example.
SELECT DISTINCT
SchemaName = SCHEMA_NAME(CAST(OBJECTPROPERTYEX(sc.object_id,'SchemaId')AS INT))
,ObjectName = OBJECT_NAME(sc.object_id)
,ColumnName = sc.name
,DataType = TYPE_NAME (sc.system_type_id)
,MaxValue = sc.last_value
,NoOfRows = p.rows
FROM sys.identity_columns sc
INNER JOIN
sys.partitions p ON sc.object_id = p.OBJECT_ID
WHERE OBJECTPROPERTYEX(sc.object_id,'IsTable') = 1
AND SCHEMA_NAME(CAST(OBJECTPROPERTYEX(sc.object_id,'SchemaId')AS INT)) LIKE 'dbo'
ORDER BY MaxValue DESC, ObjectName
I was adding e-mail code to my ASP.NET Core MVC web app and got this error when trying to send an e-mail using my O365 account.
The remote certificate is invalid according to the validation procedure.
The solution was to add the following routine.
private bool RemoteServerCertificateValidationCallback(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
//Console.WriteLine(certificate);
return true;
}
Then call it from the e-mail code like this.
//Added this line here
System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(RemoteServerCertificateValidationCallback);
SmtpClient smtp = new SmtpClient();
So altogether it looks like this.
private void sendAMail(String toAddress, String messageBody)
{
String msg = "Sending mail to : " + toAddress;
MailMessage mail = new MailMessage();
mail.To.Add(toAddress);
mail.From = new MailAddress("from@mydomain.com");
mail.Subject = "Subject: Test Mail";
mail.Body = messageBody;
mail.IsBodyHtml = true;
//Added this line here
System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(RemoteServerCertificateValidationCallback);
SmtpClient smtp = new SmtpClient();
smtp.Host = "myhostname.com";
smtp.Credentials = new System.Net.NetworkCredential("sender@sample.com", "");
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.Send(mail);
}
private bool RemoteServerCertificateValidationCallback(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
//Console.WriteLine(certificate);
return true;
}
I found the solution here: c# - "The remote certificate is invalid according to the validation procedure." using Gmail SMTP server - Stack Overflow
I went to run a PowerShell script today and I got this error message "cannot be loaded because the execution of scripts is disabled on this system." It worked previously so I was confused as to why this happened. Maybe a Windows update forced this!
It turns out that you have to execute the PowerShell command "Set-ExceptionPolicy RemoteSigned" and Choose Y for Yes when prompted. This all worked again.
I found the solution here: windows server 2008 r2 - PowerShell says "execution of scripts is disabled on this system." - Stack Overflow
When you share your folders on Windows 10/11/2022 etc. Sometimes the VLC App on your TV will not see these folders. You have to enable the SMB Server/Client features ON. This is what I had to do in order for the Shared Folders to appear in the VLC App.
Note too that I had issues connecting to the Domain Controller. I used the following format to create a link. smb://yourUsername:Password@192.168.x.x Then I had to open the link and go back twice on the Firestick remove to get into the folder!
I followed this link: VLC Network Sharing Not Working : r/VLC (reddit.com)
If you Turn on Network Discovery, click Save Settings, then review it again and it's Off again then you need to check the following 4 Services. Set them to Automatic and then start the Services. You'll hopefully find that turning on Network Discovery now stays on!!
For network discovery, it's a common issue.
Open Services and make sure the following services are all running:
- DNS Client
- Function Discovery Resource Publication
- SSDP Discovery
- UPnP Device Host
After that turn network discovery on again and it should stay enabled.
I just switched to a Windows 11 laptop (finally!) and had to setup everything again. In Visual Studio 2022 I was getting this IIS Express error "You connection is not private" error and the browser would not display my Web Site. The solution was to open Edge and type edge://flags (Chrome was chrome://flags), then find "Allow invalid certificates for resources loaded from localhost" and set it to Enabled.
I found the answer here: asp.net mvc - Your connection is not private NET::ERR_CERT_COMMON_NAME_INVALID - Stack Overflow
I recently got this error when trying to install a SharePoint CU (KB5002629) on SharePoint Subscription Edition. This is a corrupt C:\Windows\Installer folder, or maybe someone deleted some of the files/folders from this directory to save space. You should NEVER do that!! This is the error that was popping up. I tried some older CU's and got the same error.
To fix this issue you need to update the C:\Windows\Installer folder from a working server. Luckily I have a PROD and the DEV was the issue, so I was able to fix this using a script that someone kindly created.
The Script is here: This script was designed as a fix Windows "Installer" by restoring the missing Package(*.msi)/Patches(*.msp) files with the following steps: 1. Identifying the missing files. 2. Crawl the missing files from specified folder or other healthy machine. · GitHub
Someone wrote a nice blog here to explain the solution. Using PowerShell to restore Missing Windows Installer cache items (schottsql.com)
This script pulled missing files from the working sharepoint installer .\Restore-InstallerFiles.ps1 -SourceFolder "D:\InstallerFiles", "E:\InstallerFiles", "\MachineX\D$\MSI Files";
This is how to format the Date/Time with Date/Time and AM/PM in C#:
$"{DateTime.Now:yyyy-MM-dd hh:mm:ss tt}