Hackviking He killed Chuck Norris, he ruled dancing so he took up a new hobby…


Dealing with credentials in PowerShell

Whenever you write PowerShell scripts that are going to be used for automation you need to secure your credentials. The best practice is to use a service account to execute the PowerShell script and delegate whatever privileges it needs to execute. When dealing with internal systems and resources that are usually pretty easy if they all authenticate from the same ecosystem or are integrated properly. But there is instances where you need to store credentials like when working with external APIs or deattached internal system.

Continue reading...

Powershell: Manage folder permissions

Working with folder and share security is to often treated as set and forget. A good practice is to run daily jobs to check, report and reset permissions on shared folders and home directories. There are several ways to do this but it can easily be done from Powershell. This can also be used when migrating between servers and access needs to be added or removed. Here is a few useful code snippets when working with folder access and shares in Powershell.

Continue reading...


Windows: Set DNS and add to domain from command line

Just got 18 virtual servers delivered from a private cloud supplier. Since none of them are joined to our domain I need to access them one by one and set them up. After they are joined to the domain it's easier to manage them. So I wanted a quick way to add our internal DNS servers and add them to the domain. Doing this manually is a time consuming task, error prone and straight up boring. So by doing this from the command line I could do it fast, correct and less boring.

Continue reading...


Reset Windows 10 password

Upgraded one of my laptops to Windows 10 and immediately locked the admin account. Googled and found a bunch of suggestions using the Windows 10 install CD? As most other people I upgraded via the Windows 10 upgrade notice that was bugging me for months. So how do you get back into a Windows 10 machine you locked your self out of?

Before the upgrade I decrypted my boot disk and uninstalled the old Truecrypt install I had on there so accessing the disk wasn't an issue. If you have full disk encryption enabled you will not be able to use this method.

Prepair Hiren's BootCD & Boot

Hiren's BootCD contains a miniXP version that is perfect for this. Download it and follow the instructions in Launching Hiren's BootCD from USB Flash Drive. They have a really good step by step guide there. Once that is all done restart your computer from the USB drive and select "Mini Windows XP".

Prepare for password reset

Once you are booted up locate your windows boot drive. In this example I will use E:\ as the Windows boot drive. Locate the following file:


Rename it to:


Then make a copy of:


And rename it to:


You can also do this via the command prompt like this:

move d:\windows\system32\utilman.exe d:\windows\system32\utilman.exe.bak
copy d:\windows\system32\cmd.exe d:\windows\system32\utilman.exe

Then reboot your computer and let it start Windows 10.

Change the password

Once at the login screen press CTRL+ALT+DEL and click the icon for the "Utility Manager" in the lower right hand corner. This should launch a command prompt with admin rights. Just type in the following commands:

net user <username> /add
net localgroup administrators <username> /add

This will add a new account to the local admin group. Then close the command prompt and login with the new account, the password will be blank.

Clean up

Delete the C:\Windows\System32\utilman.exe and rename the utilman.exe.bak back to utilman.exe


Unable to delete file: System cannot find the file specified

Running hybrid systems spanning from windows to different flavors of Linux sometimes present you with interesting behavior. One that I have faced every now and then is files that you can't delete due to special characters in the filename. They do show up in the file explorer but when you try to delete them you get "Item not find" or similar error. Seen a lot of different solutions online with third party software and other complex solutions but there is two simple "built-in" ways to deal with this in windows.

dir /x method

Open up a cmd window and navigate to the folder in question. Run a simple dir /x command and it will list the files with the non-8dot3 short names. Then you can just go del {non-8.3-filename} and you will get rid of the file.

rd /s "\\?\c:\temp" method

Not all files generate the non-8dot3 name for some reason, don't ask me why - didn't dig that deep. For this there is a solution as well. In this scenario make sure that the files you want to get rid of are the only one/ones in the directory and run rd /s "\\?\C:\folder\containing\problem\file". This command will remove all the files and the directory as well.


How to change from IDE, ATA or RAID to AHCI

I decided to break the RAID1 on my Dell M6500 so I could run Microsoft Server 2012 R2 along with my Windows 7 installation. When the RAID was deleted I thought it would be best to switch my SATA controller over to AHCI since I'm running two Corsair Force GT SSD drives. After changing to AHCI the computer blue screens during boot. I have done it several times before but not often enough to remember what needs to be enabled. This behavior is documented in Microsoft KB922976 (Error message occurs after you change the SATA mode of the boot drive) with automatic registry fix and all. However this is not the complete solution for all situations.

According to the KB you need to enable loading of the AHCI driver, a no brainier! And also enable the Intel AHCI controller driver. But what is not included in the KB article is that the ATAPI driver also needs to be enabled for it to work. If you try to change from ATA to AHCI it is already enabled, if your computer booted with the ATA setting.

So according to the KB you should set these two registry keys to "0":


But you should also check that this one is set to "0":


You can also run these commands instead:

REG ADD HKLM\System\CurrentControlSet\Services\msahci /v Start /d 0 /f /t REG_DWORD
REG ADD HKLM\System\CurrentControlSet\Services\IastorV /v Start /d 0 /f /t REG_DWORD
REG ADD HKLM\System\CurrentControlSet\Services\atapi /v Start /d 0 /f /t REG_DWORD

Now your computer will start without the blue screen!


Windows startup error

Worked late last night, on a friday I know! One of my laptops, an XPS M1530, have been making a strange noise. The speaker locks it self in some strange scream. Sometimes I was able to get it to shut up by tapping on it but other times I had to connect headphones to get it to shut up. Last night I was tired of it so after a did the shutdown I took it apart and ripped out the broken speaker and cut out the cables. Then I put it all together again and tried to start the computer. My entire hard drive is encrypted with True Crypt and I also have a hidden operating system on the machine (both win 7 x64). On start up I got the password screen for True Crypt and entered my password for the decoy system and got this error:

Error:  error no bootable partition found

I goggled a bit and didn't find anything useful. I realized it probably was the boot properties that was messed up but none of the tools I had could access the disk because it was encrypted. So I did have the recovery cd created by True Crypt so I started it up and decrypted the entire system. Then i restored the original boot loader and tried a reboot.

Missing operating system

So I only got a new error message instead. Google didn't give me much more then that I should use the windows install cd to repair it. I have been working with windows for a long time and I don't have any good experiences with Microsoft repairs. So I didn't want to do some universal end user fix that would f*ck up my system. I booted from the windows dvd with hope of a command prompt. When I selected "Repair my system" it couldn't find my system but I could read the disk from the prompt. So I took the disk out of the computer and hooked it up to my other laptop and activated the C:\ drive of the decoy system. Now the repair function of the Windows 7 install DVD could see the installation. I got a dialog that told my that my boot options was messed up and asked me if I wanted to repair them and reboot. Yes please that would be lovely! Did it boot, of course not!

But I got even a new error! Just a blank black screen with a flashing underscore cursor. So what now? I already know that my master boot record (MBR) and probably my boot manager was broken. So I tried to boot from the Windows 7 install DVD again and issued two commands:

bootrec.exe /fixmbr
bootrec.exe /fixboot

Restarted the machine and got a new error again!
BOOTMGR is missing
But this was the first good error message so now I could really get down to fixing the issue. Started the Windows 7 installation DVD repair function again and entered the prompt. Issued the following commands:

chkdsk /r

To check for errors and "repair" them. If chkdsk finds anything the disk is usually about to fail. Really don't like when that finds anything.

Bcdedit /export C:\BCD_Backup
ren c:\boot\bcd bcd.old
Bootrec /rebuildbcd

This rebuilds the boot options for the boot manager. But this command only sacans all the disk trying to find windows installations. I couldn't see that it found anything but I could access c:\ so then i entered it manually:

bcdboot c:\windows

Then I ran bootrec again:

bootrec /fixmbr
bootrec /fixboot

Then I restarted the machine and it booted without any problem. But only my decoy system, my hidden operating system is still on a partion that looks "RAW". In my case it doesn't matter becuase I rarly used my hidden system anyway and really only created it for fun. But I think it would be possible to get the system back but I didn't try. I'm just glad that my primary system was back on track.

Tagged as: No Comments