Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Friday, 26 August 2011

Recursively remove all empty directories

In Linux:
find <parent-dir> -type d -empty -delete
Alternatives:
find <parent-dir> -empty -type d -exec rmdir {} +
find <parent-dir> -depth -type d -empty -exec rmdir -v {} +
find <parent-dir> -depth -type d -empty -exec rmdir -v {} \;

In Windows:
for /f "usebackq" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"

Possibly Related Posts

Wednesday, 13 July 2011

Shutdown a Windows machine from a Linux box

You can shutdown a windows box if you have samba installed.

Using:
net rpc SHUTDOWN -C "some comment here" -f -I x.x.x.x -U user_name%password
As long as the user you supplied has rights to shutdown the system it will work.

This bash script scans the network and turns off all systems that are left on over night.
#!/bin/bash
wks=(`nmap -sL --dns-servers 10.x.x.x,10.x.x.x 10.x.x.x/22, 10.x.x.x.x/23 grep FQDN|cut -d" " -f2 |grep -v -f serverlist`)
for (( i=0; i < "${#wks[@]}"; i++)); do
net rpc SHUTDOWN -C "This system was left on after hours and is being shutdown" -f -I "${wks[$i]}" -U user_name%password
done
Basically what the script does is scans the network(s) with nmap, pipes it though grep and cut to get the FQDN. Then "grep -v -f serverlist" is an exclude list of servers we don't want to shutdown. From there it puts the workstations into an array and turns off each system.

Possibly Related Posts

Wednesday, 6 July 2011

Upgrading Windows Server 2008 R2 Edition without media

You can accomplish this using DISM command line tool:

To determine the installed edition, run:
DISM /online /Get-CurrentEdition
To check the possible target editions, run:
DISM /online /Get-TargetEditions
Finally, to initiate an upgrade, run:
DISM /online /Set-Edition:<edition ID> /ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
So, for example, to upgrade to Windows Server 2008 R2 Datacenter from a Standard edition, you would run:
DISM /online /Set-Edition:ServerDatacenter /productkey:ABCDE-ABCDE-ABCDE-ABCDE-ABCDE
After running the /Set-Edition command, DISM will prepare the operating system for the edition servicing operation, then reboot twice while it applies the changes to the operating system. After the final reboot, you’ll be running the new edition!

Note: that the server can't be a DC at the time of upgrade. If you demote a DC using dcpromo, you can upgrade, then re-promote it (you may need to migrate FSMO roles, etc, in order to succesfully demote.)

Possibly Related Posts

Thursday, 26 May 2011

Remove GRUB from Windows

Put the Windows Install Disk into the drive and boot it up, select your language, select repair, select which partition/instalation to repair, click open Dos (last option on the list), type the following:
bootrec.exe /FixMbr

Possibly Related Posts

Monday, 23 May 2011

Delete files older than... in windows

You can use robocopy:
ROBOCOPY C:\work C:\trash /move /minage:14
or xcopy
xcopy *.* /d:04-12-2006 C:\trash
and at the end:
rmdir /s /q C:\trash

Possibly Related Posts