26 May 2017

How to manually add Java exception sites

 

Type in Start + Run window:

notepad %localappdata%low\sun\java\deployment\security\exception.sites

image

Then type all the addresses you want to open with Java without security error. It’s useful for example with Intel server motherboards.

image

11 May 2017

How to convert dynamic IP configuration to static using PowerShell

For example to start running DHCP or DNS server, you need to have static IP configuration. If you already have an DHCP Server configured IP configuration, you might want to use the same IP address and DNS configuration. To do this automatically, use this script:

$nic = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | ogv –PassThru

#convert to static
$IPAddress = $nic.IPAddress[0]
$IPSubnet = $nic.IPSubnet[0]
$DefaultIPGateway = $nic.DefaultIPGateway
$DNSServerSearchOrder = $nic.DNSServerSearchOrder
$nic.EnableStatic($IPAddress, $IPSubnet)
$nic.SetGateways($DefaultIPGateway)
$nic.SetDNSServerSearchOrder($DNSServerSearchOrder)

#enable dhcp for ip and dns
$nic.EnableDHCP()
$nic.SetDNSServerSearchOrder()

First section is for selecting the correct network adapter. By running the second section, the current information is copied as static configuration. By running the third part, DHCP default configuration is set.

05 May 2017

How to remove empty folders using PowerShell

To remove empty folders from your D: drive, use following command:

$folders = gci d:\ -r | ? PSIsContainer -eq $True
$folders.Count
$emptyfolders = $folders | ? {$_.GetDirectories().Count -eq 0 -and $_.GetFiles().Count -eq 0}
$emptyfolders.Count
$emptyfolders | select * | ogv
$emptyfolders | Remove-Item

It has some room for improvement (i had to do multiple passes, because after cleaning up some other folders appeared empty (before they contained only empty folders inside it). And dont use it on C: drive, there might be useful empty folders.

01 May 2017

Schedule nightly restart using PowerShell

To register a nightly job:

Register-ScheduledJob restart {Restart-Computer -Force} -Trigger (New-JobTrigger -At 01:00 -Daily) -ScheduledJobOption (New-ScheduledJobOption -RunElevated)

To unregister the nightly job:

Unregister-ScheduledJob restart

To view jobs, use taskschd.msc (Task Scheduler) and go to \Microsoft\Windows\PowerShell\SceduledJobs folder and fine tune them if needed.