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.

05 April 2017

Get screen resolutions and positions using PowerShell

To get screen resolutions and positions using powershell, you can use this oneliner:

Add-Type -A System.Windows.Forms;[System.Windows.Forms.Screen]::AllScreens|ft *d*

In my example I have this screen layout:

image

The output in my case is like this:

image

07 February 2017

How to bulk change Calendar permissions in Exchange 2013 using PowerShell

Let’s assume, that you want to let some group of users see each others calendars. Instead of instructing each user to change calendar permissions using Outlook, you can do it for them.

First lets try to see current permissions:

$users = Get-DistributionGroupMember groupname@contoso.com | select -ExpandProperty PrimarySmtpAddress
foreach ($user in $users)
{$folder = $user + ':\' + (Get-MailboxFolderStatistics $user | where foldertype -eq calendar).name
"------------------------------------------------------------------------------------------------"
$folder
Get-MailboxFolderPermission $folder
}


It will produce similar output:
image

To add permissions, you simply need to change the get cmdlet to add cmdlet:

$users = Get-DistributionGroupMember groupname@contoso.com | select -ExpandProperty PrimarySmtpAddress
foreach ($user in $users)
{$folder = $user + ':\' + (Get-MailboxFolderStatistics $user | where foldertype -eq calendar).name
"------------------------------------------------------------------------------------------------"
$folder

Add-MailboxFolderPermission $folder -User groupname@contoso.com -AccessRights reviewer
Set-MailboxFolderPermission $folder -User groupname@contoso.com -AccessRights reviewer
}

Add and Set are both present because if the permission is already present, then first command will fail. If you want to use default calendar permissions, the mailboxpermission cmdlets should have ‘-User Default’ in the middle. If you want to change calendar permissions on all users, then instead of get-distributiongroupmember you should use get-mailbox instead.

21 April 2016

How to get the neighboring computer to talk using psexec, PowerShell and System.Speech

Let’s assume, you have domain network and you are using domain admin to do the trick. Also the neighbors computer must be running quite fresh windows version (i tried windows 10 only, let me know when older ones also work).

First of all you need psexec from sysinternals to run something on other computer. http://live.sysinternals.com/ is one good starting point for getting that tool.

Next open your command prompt as the domain admin user and type the following command (yes, it is a one-liner):

psexec \\neighbor cmd /c powershell [Reflection.Assembly]::LoadWithPartialName('System.Speech');$object = New-Object System.Speech.Synthesis.SpeechSynthesizer;$object.Speak('i know what you did last summer')

where neighbor is the name of the neighboring computer and last string is the text to speak. After some waiting the neighboring computer should talk to the default audio device.