Category Archives: PowerShell

Block Outlook from connecting to 365

By | August 10, 2021

Beginning with Office 2016 Outlook auto-connects to 365 upon opening. This causes users to be prompted for credentials if their account is on-premise. To disable this,  run this in PowerShell as the user: Set-ItemProperty -Path HKCU:\software\Microsoft\Office\16.0\Outlook\AutoDiscover -Name ‘ExcludeExplicitO365Endpoint’ -Value 1 -Type DWord -Force

Keep Mapped Location Open

By | November 22, 2020

If windows continually drops a remote location you can keep it open with this: do{start-process \\server\path ;start-sleep 5 $a = (New-Object -comObject Shell.Application).Windows() |?{$_.FullName -ne $null} |? {$_.FullName.toLower().Endswith(‘\explorer.exe’)} $a | % {  $_.Quit() }Start-sleep 3600}while ($True)

Set Network Type

By | July 16, 2019

To change the network type in windows 10 from Public to Private: $Name = Get-NetConnectionProfile|Select Name |out-gridview -PassThru Set-NetConnectionProfile -Name $ -NetworkCategory Private

Making PowerShell Interactive

By | January 11, 2019

Turn a Powershell script into an interactive application with: Out-GridView -PassThru | This code will pause your script and present you the data collected in a grid view. You can then select specific items in that view. When you hit OK at the bottom the script will proceed against just the selected items.

AnyConnect Password

By | August 23, 2018

The Cisco Any Connect Client does not allow you to save a password on the client. This code when saved as a .vbs file will let you get around this.  Be warned that the client’s password is saved in clear text in the file. I hide the file in Drivers and create a shortcut to it with the… Read More »

Exchange Permissions

By | August 16, 2018

You can list all users with Mailbox permissions with this in PowerShell: Get-Mailbox | Get-MailboxPermission | where {$_.user.tostring() -ne “NT AUTHORITY\SELF” -and $_.IsInherited -eq $false} | Select Identity,User | Export-Csv -NoTypeInformation mailboxpermissions.csv

Safe Mode from CMD

By | April 8, 2018

If you need to put a system into safe mode you can do this from cmd then reboot: This will set the safemode switch: bcdedit /set {current} safeboot minimal with networking: bcdedit /set {current} safeboot network to put back in normal mode via dos: bcdedit /deletevalue {current} safeboot

Remote log off

By | March 20, 2018

I recently had a console session hang with just a white screen and no start menu on an Exchange Server. Not wanting to reboot the server and disrupt the entire office, I used the following to remotely log the admin out via PowerShell: (gwmi win32_operatingsystem -ComputerName $PCname).Win32Shutdown(4)

Exchange Email Format

By | May 9, 2017

In Exchange, emails sent outside the organization are converted and the format of these can be set per domain or for all domains. If messages are sent in text format, some recipients will have issues viewing attached images. ContentType should be MimeHtmlText not MimeText when running: Get-RemoteDomain |fl To update it run the following with either a domain… Read More »

Clean All Temp Folders

By | February 28, 2017

$tempfolders = @(“C:\Windows\Temp\*”, “C:\Windows\Prefetch\*”, “C:\Documents and Settings\*\Local Settings\temp\*”, “C:\Users\*\Appdata\Local\Temp\*”,”C:\ProgramData\Microsoft\Windows\WER\ReportArchive\*”); Remove-Item $tempfolders -force -recurse

Exporting Mailboxes

By | January 18, 2017

You can export entire mailboxes (smaller than 50GB) to PST, from the Exchange console: New-MailboxExportRequest -Mailbox “Amy Smith” -FilePath “\\Server\Share\AmySmith.pst” To get Status of the request: Get-MailboxExportRequest | Get-MailboxExportRequestStatistics | fl These should be output to a fast drive with plenty of capacity (not a shadow copy volume). When decommissioning a user account move the file  to the… Read More »

Disable Hibernation

By | October 18, 2015

Windows default has hibernation turned on. This take good piece of the hard drive in the form of the hiberfil.sys file which takes up about as much c drive space as there is RAM installed. To dispose of the file and disable hibernation instantly use this in PowerShell: powershell -Command “Start-Process ‘powercfg.exe’ -Verb runAs -ArgumentList ‘/h off'”

Search for PSTs

By | March 18, 2015

Before removing a drive from service or when moving a user to a new system, it is important to verify no PSTs have been left behind. To find all PSTs launch ISE as admin then run: Get-ChildItem -path c:\users\ -force -Recurse -filter ‘*.pst’ -erroraction ‘silentlycontinue’ | select name, Length, LastWriteTime, directory #Run as admin  

Set Outlook permisions

By | March 9, 2015

In this example abaldwin is granted reviewer access to jjohnson’s calendar: get-mailbox -identity “jjohnson”| foreach {Add-MailboxfolderPermission $_”:\calendar” -User “abaldwin” -AccessRights Reviewer} To do this for an entire Co. use Excel and a list of all users then use Concatenate to edit the individual cmdlets which can be pasted in bulk to PowerShell.

Exchange 2013 Error “X-FEServer:”

By | January 23, 2015

This is caused after a new SSL Certificate is installed on Exchange. To resolve this go to IIS MMC find the certificate hash for the new cert then run the following PowerShell commands: Enable-ExchangeCertificate CertificateHash -Services SMTP Enable-ExchangeCertificate CertificateHash -Services IIS