Posts

Showing posts from December, 2017

Get-LocalGroupMember PowerShell cmdlet issues - An unspecified error occurred: error code = 1789

Image
We've recently been working on the new local account management PowerShell cmdlets and found an issue with the Get-LocalGroupMember cmdlet If a user group has a member that cannot be resolved normally most APIs will return just the SID of the account, and certainly the Computer Management MMC shows the user as the SID and as an unknown account. Unfortunately the  Get-LocalGroupDetails PowerShell cmdlet fails completely with the following error  Get-LocalGroupDetails. An unspecified error occurred: error code = 1789 If you use an -ErrorAction SilentlyContinue parameter the cmdlet will return with no members which is obviously misleading as there may be other, valid accounts in the group.

How to relock a Bitlocker drive after you've unlocked it with PowerShell

Image
If you're using Windows Server 2012 or above you can use PowerShell to relock a bitlocker drive that you have already unlocked Lock-BitLocker E: However if the drive is in use you may see this error Lock-BitLocker : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) At line:1 char:1 + Lock-BitLocker E: + ~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [Write-Error], UnauthorizedAcc    essException     + FullyQualifiedErrorId : System.UnauthorizedAccessException,Lock-BitLocke    r   This is simple to resolve - simply add the -ForceDismount parameter Lock-BitLocker E: -ForceDismount   

Running start in a batch file or .cmd file displays a command prompt instead of running the application.

I've recently run into an issue whereby I'm trying to start several Visual Studio environments as another user with the runas command for remote testing. So I created a batch file with the runas command which then launches a second batch file that starts 4 instances of Visual Studio. @echo off cls start "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe" start "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe" start "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe" start "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe" However instead 4 command prompt windows are loaded. When you run the same command live inside a command prompt it works. This is a case of not reading the documentation! The first parameter of the start command is the window title, so you need two double quo...

System.IO.File.ReadAllText method and Default encoding with Nano server

Image
You may find that running the following command on Nano will fail [System.IO.File]::ReadAllText($path, [System.Text.Encoding]::Default) Exception calling "ReadAllText" with "2" argument(s): "Value cannot be null. This is because the Default encoding is not longer in the list of valid encoding types To resolve this issue either call ReadAllText with no parameter, or a different encoding parameter. Or better still use the Get-Content cmdlet which takes the pain away from this encoding.