23. februar 2023

Shrink SQL log

To find database file names use below query

select * from sys.database_files; 



USE {database-name};  

GO  
-- Truncate the log by changing the database recovery model to SIMPLE.  
ALTER DATABASE {database-name}
SET RECOVERY SIMPLE;  
GO  
-- Shrink the truncated log file to 1 MB.  
DBCC SHRINKFILE ({database-file-name}, 1);  
GO  
-- Reset the database recovery model.  
ALTER DATABASE {database-name}
SET RECOVERY FULL;  
GO

23. januar 2023

Powershell - Delete files older than "$Days" days

#---- Delete files in $Path older than $Days ----#
$Path = "C:\Temp"
$Days = "30"
dir $Path -ErrorAction SilentlyContinue | Where { ((Get-Date)-$_.LastWriteTime).days -gt $Days } | Remove-Item -Force -WhatIf

Recursive delete :
dir $Path -recurse -ErrorAction SilentlyContinue | Where { ((Get-Date)-$_.LastWriteTime).days -gt $Days } | Remove-Item -Recurse -Force -WhatIf


Remark : Parameter "-WhatIf" is there only for testing, remove when sure it deletes right files
TEST IN Powershell ISE before deleting wrong files

22. november 2022

Skift fra Public til Privare network (Powershell)

Sommetider starter Windows servere op med Public Network og er derfor ikke kontaktbar (pga. firewall indstillinger)

Dette kan som regel løses ved at genstarte Network Location Awareness servicen.
Sæt den herefter til "Delayed start" og alle 3 recovery til "Restart service"

Powershell

Get-NetConnectionProfile


If you have only one network connection you can change the profile to private by typing:

Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private


If you have multiple network interfaces and would like to change a specific adapter use the Interface Index Property like this:

Set-NetConnectionProfile -InterfaceIndex 3 -NetworkCategory Private


The same command also works to switch back to a public profile

Set-NetConnectionProfile -InterfaceIndex 3 -NetworkCategory Public

2. august 2022

Office365 cached Exchange 3 days

https://admx.help/?Category=Office2016&Policy=outlk16.Office.Microsoft.Policies.Windows::L_CachedExchangeModeSyncSlider

HKEY_CURRENT_USERsoftware\policies\microsoft\office\16.0\outlook\cached modesyncwindowsettingdaysREG_DWORD3

6. juli 2022

Send e-mail from powershell - with TLS !

$body = "tester email fra powershell"

$fromaddress = "someone@somewhere.com"

$toaddress = "receiver@anywhere.com"

$subject = "test mail"

$smtp = "smtp.office365.com"

$port = "587"

Send-MailMessage -from $fromaddress  -to $toaddress -subject $subject -body $body -BodyAsHtml -UseSsl -Credential (Get-Credential)  -smtpServer $smtp -port $port

16. maj 2022

What to Do When a Deleted User Still Appears on the Windows 10/11 Login Screen?

If the user has been deleted and still appear on logon screen :

Run NetPlWiz.exe

Select User must use Ctrl+Alt+Del to logon, on advanced tab, click Ok

Reboot

Run NetPlWiz.exe

Un-select User must use Ctrl+Alt+Del to logon, click Ok

Reboot