Copy vswitch information between ESX servers

Below is a script to copy vswitch information from a source ESX server to a destination ESX server.

All vswitch, network and vlan information will be copied.

# Define Variables 
$VCServer = "vc-server" 
$cred = Get-Credential

# Connect server 
$VC = Connect-VIServer -Server "$VCServer" 

#$VISRV = Connect-VIServer (Read-Host "Please enter the name of your VI SERVER")
$BASEHost = Get-VMHost -Name (Read-Host "Please enter the name of your existing server as seen in the VI Client:")
$NEWHost = Get-VMHost -Name (Read-Host "Please enter the name of the server to configure as seen in the VI Client:")

$BASEHost |Get-VirtualSwitch |Foreach {
   If (($NEWHost |Get-VirtualSwitch -Name $_.Name-ErrorAction SilentlyContinue)-eq $null){
       Write-Host "Creating Virtual Switch $($_.Name)"
       $NewSwitch = $NEWHost |New-VirtualSwitch -Name $_.Name-NumPorts $_.NumPorts-Mtu $_.Mtu
       $vSwitch = $_
    }
   $_ |Get-VirtualPortGroup |Foreach {
       If (($NEWHost |Get-VirtualPortGroup -Name $_.Name-ErrorAction SilentlyContinue)-eq $null){
           Write-Host "Creating Portgroup $($_.Name)"
           $NewPortGroup = $NEWHost |Get-VirtualSwitch -Name $vSwitch |New-VirtualPortGroup -Name $_.Name-VLanId $_.VLanID
        }
    }
}

 

PS: Get last logon time on exchange

To get the last logon time for a user in exchange use the following powershell script:

Get-MailboxStatistics -identity "Joe smith" | select-object displayname, lastlogontime

If you want to see the lastlogontime for all users in a Distribution group, use the following powershell script:

 

$usergroup = Get-DistributionGroupMember -identity "DL name" -domaincontroller dcname

foreach ($user in $usergroup) { Get-MailboxStatistics -identity $user.samaccountname | select-object displayname, lastlogontime}

 

Powershell: Enable Remote Desktop on a Windows 2012 machine

Run the following Powershell commands to enable remote desktop.

#Enable Remote Desktop
Invoke-Command -computername localhost -scriptblock {(gwmi -class win32_terminalservicesetting -namespace "root\cimv2\terminalservices").setallowtsconnections(1)}

#Configure Firewall for Remote Desktop
Invoke-command -computername localhost -scriptblock {netsh advfirewall firewall set rule group="remote desktop" new enable=Yes }

 

Powrshell: Show user info from groupmembers

Use the following powershell script to display the samaccount, name, mail information from all groupmembers. Also show if the account is enabled.

 

import-module activedirectory
Get-ADGroupMember “GROUP” | select samaccountname | %{Get-ADUser $_.samaccountname -Properties mail} | format-table samaccountname,name,mail,enabled

 

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/

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

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

SCRIPT – Computer Inventory

The Computer Inventory Script enumerates Hardware, OS, System, Processor, Memory, Disk, and Network information and neatly organizes it in an Excel file. I’ve provided Version 2 of the script that allows you to choose a number of computer resources; all computers in the domain, all servers in the domain, computers from a list maintained in a text file, and the ability manually pick a computer. Version 2 of the PowerShell script also allows you to send credential information should you wish to logon the remote computer with an alternative user account. This is helpful for DMZ servers as well as stand alone servers that are not members of your domain.

source: http://www.powershellpro.com/why-i-no-longer-hate-writing-documentation/614/

 

[wpdm_file id=78]