Getting the Directory Size on Remote Servers.

Use the following script:

 

$dataColl = @()#Makes an array, or a collection to hold all the object of the same fields.

foreach ($serverName in (get-content "c:\servers.txt"))

{
$path = "\\$serverName\f$\temp"
$dirSize = Get-ChildItem $path -recurse -force | select Length |Measure-Object -Sum -property length
$dirSize.sum = $dirSize.sum/1GB
$finalResult = "{0:N2} GB" -f $dirsize.sum
$dataObject = New-Object PSObject
Add-Member -inputObject $dataObject -memberType NoteProperty -name "ServerName" -value $serverName
Add-Member -inputObject $dataObject -memberType NoteProperty -name "Dir_Size" -value $finalResult
$dataColl += $dataObject
$dataObject
}

$dataColl | Out-GridView -Title "Remote Directory Scan Results"
$dataColl | Export-Csv -noTypeInformation -path "c:\temp.csv"

 

to workaround the error: Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

 

use the following script:

$dataColl = @()#Makes an array, or a collection to hold all the object of the same fields.

foreach ($serverName in (get-content "c:\servers.txt"))

{
$path = "\\$serverName\f$\data"
#$dirSize = Get-ChildItem $path -recurse -force | select Length |Measure-Object -Sum -property length
$dirSize = (robocopy.exe $path $env:Temp /zb /e /l /r:1 /w:1 /nfl /ndl /nc /fp /bytes /np /njh | ? {$_ -match "Bytes :"}).trim().split(" ")[2]
$dirsum = $dirSize/1GB
$finalResult = "{0:N2} GB" -f $dirsum
$dataObject = New-Object PSObject
Add-Member -inputObject $dataObject -memberType NoteProperty -name "ServerName" -value $serverName
Add-Member -inputObject $dataObject -memberType NoteProperty -name "Dir_Size" -value $finalResult
$dataColl += $dataObject
$dataObject
}

$dataColl | Out-GridView -Title "Remote Directory Scan Results"
$dataColl | Export-Csv -noTypeInformation -path "c:\temp.csv"

 

source: http://thescriptlad.com/2011/04/16/get-remote-dir-size/

Excel – Count colored cells

Copy and paste the following code into you VBA project (alt+f10 in excel)

 

Public Function cell_colour(Cell_Check As Range) As Long
cell_colour = Cell_Check.Interior.Color
End Function

Public Function count_colour(Count_Range As Range, Colour As Long) As Long
Dim x As Range
count_colour = 0
For Each x In Count_Range
If x.Interior.Color = Colour Then
count_colour = count_colour + 1
End If
Next x
End Function

 

With the formula “count_colour(B1:B10;cell_colour($A$1))” you can count the colorourd cells in B1 to B10 with the same colour as the cell in A1

KMS Client Setup Keys

Computers that are running volume licensing editions of Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Vista, and Windows Server 2008 are, by default, KMS clients with no additional configuration needed.

If you are converting a computer from a KMS host, MAK, or retail edition of Windows to a KMS client, install the applicable setup key (GVLK) from the following tables

To install a client setup key, open an administrative command prompt on the client, type slmgr /ipk <setup key> and press ENTER.

Operating system edition KMS Client Setup Key
Windows 8 Professional NG4HW-VH26C-733KW-K6F98-J8CK4
Windows 8 Professional N XCVCF-2NXM9-723PB-MHCB7-2RYQQ
Windows 8 Enterprise 32JNW-9KQ84-P47T8-D8GGY-CWCK7
Windows 8 Enterprise N JMNMF-RHW7P-DMY6X-RF3DR-X2BQT
Windows Server 2012 Core BN3D2-R7TKB-3YPBD-8DRP2-27GG4
Windows Server 2012 Core N 8N2M2-HWPGY-7PGT9-HGDD8-GVGGY
Windows Server 2012 Core Single Language 2WN2H-YGCQR-KFX6K-CD6TF-84YXQ
Windows Server 2012 Core Country Specific 4K36P-JN4VD-GDC6V-KDT89-DYFKP
Windows Server 2012 Server Standard XC9B7-NBPP2-83J2H-RHMBY-92BT4
Windows Server 2012 Standard Core XC9B7-NBPP2-83J2H-RHMBY-92BT4
Windows Server 2012 MultiPoint Standard HM7DN-YVMH3-46JC3-XYTG7-CYQJJ
Windows Server 2012 MultiPoint Premium XNH6W-2V9GX-RGJ4K-Y8X6F-QGJ2G
Windows Server 2012 Datacenter 48HP8-DN98B-MYWDG-T2DCC-8W83P
Windows Server 2012 Datacenter Core 48HP8-DN98B-MYWDG-T2DCC-8W83P
Operating system edition KMS Client Setup Key
Windows 7 Professional FJ82H-XT6CR-J8D7P-XQJJ2-GPDD4
Windows 7 Professional N MRPKT-YTG23-K7D7T-X2JMM-QY7MG
Windows 7 Professional E W82YF-2Q76Y-63HXB-FGJG9-GF7QX
Windows 7 Enterprise 33PXH-7Y6KF-2VJC9-XBBR8-HVTHH
Windows 7 Enterprise N YDRBP-3D83W-TY26F-D46B2-XCKRJ
Windows 7 Enterprise E C29WB-22CC8-VJ326-GHFJW-H9DH4
Windows Server 2008 R2 Web 6TPJF-RBVHG-WBW2R-86QPH-6RTM4
Windows Server 2008 R2 HPC edition TT8MH-CG224-D3D7Q-498W2-9QCTX
Windows Server 2008 R2 Standard YC6KT-GKW9T-YTKYR-T4X34-R7VHC
Windows Server 2008 R2 Enterprise 489J6-VHDMP-X63PK-3K798-CPX3Y
Windows Server 2008 R2 Datacenter 74YFP-3QFB3-KQT8W-PMXWJ-7M648
Windows Server 2008 R2 for Itanium-based Systems GT63C-RJFQ3-4GMB6-BRFB9-CB83V
Operating system edition KMS Client Setup Key
Windows Vista Business YFKBB-PQJJV-G996G-VWGXY-2V3X8
Windows Vista Business N HMBQG-8H2RH-C77VX-27R82-VMQBT
Windows Vista Enterprise VKK3X-68KWM-X2YGT-QR4M6-4BWMV
Windows Vista Enterprise N VTC42-BM838-43QHV-84HX6-XJXKV
Windows Web Server 2008 WYR28-R7TFJ-3X2YQ-YCY4H-M249D
Windows Server 2008 Standard TM24T-X9RMF-VWXK6-X8JC9-BFGM2
Windows Server 2008 Standard without Hyper-V W7VD6-7JFBR-RX26B-YKQ3Y-6FFFJ
Windows Server 2008 Enterprise YQGMW-MPWTJ-34KDK-48M3W-X4Q6V
Windows Server 2008 Enterprise without Hyper-V 39BXF-X8Q23-P2WWT-38T2F-G3FPG
Windows Server 2008 HPC RCTX3-KWVHP-BR6TB-RB6DM-6X7HP
Windows Server 2008 Datacenter 7M67G-PC374-GR742-YH8V4-TCBY3
Windows Server 2008 Datacenter without Hyper-V 22XQ2-VRXRG-P8D42-K34TD-G3QQC
Windows Server 2008 for Itanium-Based Systems 4DWFP-JF3DJ-B7DTH-78FJB-PDRHK

 

source: http://technet.microsoft.com/en-us/library/jj612867.aspx

 

Using the Exchange 2010 SP1 and SP2 Mailbox Export features for Mass Exports to PST files

 

Export:

set-adserversettings -viewentireforest $true

new-mailboxexportrequest -mailbox “mailboxname” -Isarchive -filepath \\uncpath\archive.pst -mrsserver server

new-mailboxexportrequest -mailbox “mailboxname” -filepath \\uncpath\mailbox.pst -mrsserver server

 

Status:

get-mailboxexportrequest -mailbox “mailboxname” | Get-MailboxExportRequestStatistics

 

See http://www.stevieg.org/2010/07/using-the-exchange-2010-sp1-mailbox-export-features-for-mass-exports-to-pst/ for a mass export

Uninstall software on remote computers using WMIC

  • In a window, type Runas /user:YourUsername@UPNsuffix cmd.exe (or Runas /user:domain\username cmd.exe) where YourUsername is your domain admin username or any username with admin privileges on the remote computer and UPNsuffix is your UPN suffix. Let’s suppose I use [email protected]
  • In the command prompt window type the password for user [email protected] and press Enter
  • Type WMIC
  • Now, list all Nokia software on a specific computer using the command /node:COMPUTERNAME product where vendor=”Nokia” get name, version
  • Once we know the software name, we can uninstall specific product using the following command /node:COMPUTERNAME product where name=”Nokia PC Suite” call uninstall. You will see a message like Execute (\\COMPUTERNAME\ROOT\CIMV2:Win32_Product.IdentifyingNumber=”{225DB4AA-3CFF-47E8-B3C8-6DAD713E986E}”,Name=”Nokia PC Suite”,Version=”7.1.51.0″)->Uninstall() (Y/N/?)? Type Y and wait for the result.

 

http://community.spiceworks.com/how_to/show/179-using-a-command-line-to-uninstall-software-on-remote-pcs

Windows Server 2012 GUI

http://blogs.technet.com/b/askds/archive/2012/09/20/windows-server-2012-shell-game.aspx

 

Adding Server Graphical Shell and Graphical Management Tools and Infrastructure

Install-WindowsFeature server-gui-mgmt-infra,server-gui-shell -source:wim:d:\sources\install.wim:2

 

Use 2 for standard and 4 for a datacenter edition and make sure D is the drive with the DVD with Windows Server 2012.

Windows 2012 – CLI

Activating Windows 2012 with powershell:

(or use sconfig)

slmgr.vbs –ipk <productkey>
slmgr.vbs –ato

 

Rename the sever:
  • Determine the current name of the server with the hostname or ipconfig command.
  • In Windows PowerShell, run Rename-Computer.
  • Restart the computer.

 

Installing GUI with powershell:

(or use sconfig)

Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra

An other option is to use dism

Dism /online /enable-feature /featurename:ServerCore-FullServer /featurename:Server-Gui-Shell /featurename:Server-Gui-Mgmt

If this fail, you need to mount the files.

1. Create a folder to mount WIM (mkdir c:\mountdir)

2. Check the index number needed for a server with GUI image (where d is the DVD drive)

dism /get-wiminfo /Wimfile: d:\sources\install.wim

We want to install the SERVERSTANDARD so the index number will be 2

3. Mount the WIM for Server Standard:

dism /mount-wim /wimfile: d:\sources\install.wim /Index:2 /mountdir:c:\mountdir /readonly

4. Start powershell and execute:

Install-WindowsFeature Server-Gui-Mgmt-Infra, Server-Gui-Shell –restart –source c:\mountdir\windows\winsxs

5. Restart the server

 

 

Remove the GUI with powershell:
Uninstall-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra

 

SCONFIG

Use SCONFIG to configure a lot of options (domain/Computername/updates/nic/…)

 

For other options to remove/install the GUI look at http://www.howtogeek.com/111967/how-to-turn-the-gui-off-and-on-in-windows-server-2012/

Configure a Server Core Server: http://technet.microsoft.com/en-us/library/jj592692.aspx#BKMK_1_5