22 September 2014

Biggest Free E-Book collection online, and download them all with Powershell

I came across this blog: http://blogs.msdn.com/b/mssmallbiz

It lists almost 300 free e-books:

Windows 8.1
Windows 8 
Windows 7 
Office 2013
Office 365
Office 2010
SharePoint 2013 
Dynamics CRM
PowerShell
Exchange Server
Lync 2013
System Center
Azure 
Cloud
SQL Server

and much more.
Nice to have right?
But since you have to download them one by one, i found this script in the comments (Thanks Todd) and it works like a charm.

First download the MSFTEbooks.txt file from here
Then paste the below Powershell script directly in Powershell or run it from a ps1 file.
Edit your file locations to your corresponding folder locations.

Requires Powershell v3.0:

$booklist = Get-Content "D:\_DATA\Scripts\MSFTEbooks.txt"

$destination = "D:\_DATA\Downloads\E-Books"

foreach ($url in $booklist){

   if ($url.StartsWith("http")){
       $result = Invoke-WebRequest -Uri $url -outfile $destination\temp.tmp -PassThru
       if ($result.statuscode -eq "200"){
           $filename = join-path $destination (Split-Path -leaf ($result.BaseResponse.ResponseUri))
           Write-Host $filename
           Rename-Item $destination\temp.tmp $filename
       }
   }
}

While downloading it looks like this:



18 September 2014

Enable Powershell remoting and access denied

To check if Powershell Remoting is turned on:
Enter-PSSession -ComputerName localhost If all goes well the output is shown like this:
[PS] C:\Windows\system32>Enter-PSSession -ComputerName localhost [localhost]: PS C:\Users\Username\Documents> In some cases you get an error stating that "Access denied", but doenst really give enough info on why access is denied. From an elevated command prompt run the following command:
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f After that, re-launch the Powershell prompt as admin and re-run Enable-PSSRemoting

16 September 2014

Clean scan engine folders for Forefront Protection for Exchange 2010

How to clean up the Forefront folders for all the scan engines used by Forefront.

Disk space can be hogged by these folder even though the update mechanism built in Forefront itself is configured to delete the old and obsolete scan-engines and pattern files.

If for some reason the disks are filling up, you can manually clean up the folders (delete its content really) and after that the update mechanism downloads the needed engines and patterns automatically.

First stop all related Exchange services:
get
-service *exchange*|stop-service
The stop all related Forefront services:
get-service *fpe*|stop-service

Then delete all files in
c:\Program Files (x86)\Microsoft Forefront Protection for Exchange Server\Data\Engines\x86
&
c$\Program Files (x86)\Microsoft Forefront Protection for Exchange Server\Data\Engines\amd64

Restart the server, reenable automatic management of updates, or manually start the update process.
Watch the folders getting filled with the latest patterns and engines.

10 September 2014

Using Hyper-V with a Wireless Network Adapter

Out of the box Hyper-V does not support connecting virtual machines to wireless network adapters.  As a primarily server focused product this is a reasonable limitation - especially given that we need to do to get wireless network adapters to work with virtual machines.  But all is not lost - it is possible to setup an internal virtual network and utilize Internet Connection Sharing to get you up and going.
The first thing to do is to create a new internal virtual network switch:
  1. Open the Hyper-V Manager and select your server.
  2. Select Virtual Network Manager... from the action pane (on the right).
  3. Select New virtual network and choose to Add an Internal network.
  4. Give the new virtual network the name you want hit OK.
Now to setup Internet Connection Sharing:
  1. Open the Control Panel and open Network and Sharing Center.
  2. Select Manage network connections from the list on the left.
  3. Locate the icon for your wireless network adapter, right click on it and select Properties.
  4. Change to the Sharing tab.
  5. Check Allow other network users to connect through this computer's Internet connection.
  6. If you have multiple network adapters you will need to select the specific entry for the internal virtual network switch.
  7. Click OK.
You can now connect virtual machines to the internal virtual network and allow them to access the Internet through your wireless network adapter.

Source

Install Windows Server 2008 R2 on VHD bual boot on Windows 7

Great article on TechRepublic:

How to install Windows Server 2008 R2 with yper-V and Windows 7 on the same partition


By Colin Smith in Data Center, September 20, 2010
Blogger Colin Smith explains how to install Windows Server 2008 R2 with Hyper-V and Windows 7
on the same disk partition by booting from a VHD that contains the entire WS2K8R2 OS 
within a single, portable file.

Typically, dual-booting multiple operating systems requires repartitioning a disk, which isn't always
desirable, especially if you already have a multi-boot environment with Windows and Linux. What 
I am proposing is booting from a VHD - a virtual hard disk that contains the entire Windows Server
2008 R2 OS installation within a single, portable file hosted by your Windows 7 file system.What's
different about this post from the other boot-from-VHD posts out there? Admittedly, I did learn how
to create and install into VHD from some of the TechNet posts, but they focus on creating VHDs from within the WinPE console. Unfortunately, most of us work in Windows, not WinPE. 
So, what I have attempted here is to show you how to create the VHD from Windows 7 (or Windows Server 2008 R2), so that you can create VHDs for other purposes in addition to just an OS install. Additionally, I'll try to provide some other scenarios where you might want to consider using VHDs.

Why would you want to boot from a VHD?
There are several reasons:

  • There is no requirement to repartition your hard drive, which in itself tends to waste disk space since most partitions are typically over provisioned.
  • It simplifies image management for both VMs and physical systems as the same VHDs can be repurposed for both use cases.
  • You can move the VHD to a Hyper-V server or port it to another virtualization platform like ESX, Virtual Box, Xen , etc., that supports VHDs.
  • The VHD can be configured to be thin provisioned. This means that you can set the maximum size of the VHD and it will appear to the guest OS as a full partition, but in the host OS, it will only consume as much disk space as required to contain the entire guest OS. The VHD will grow in size up to the maximum as blocks are written to (allocate on write).
  • You can remove the entire OS by simply removing a single file and updating your boot menu.
  • It allows you to boot easily from an external device like an eSATA drive (USB or remote storage are not supported for Windows 7 or Windows Server 2008 R2 - Hyper-V Server is supported on USB/Flash )
  • You can easily back up the entire OS as a single file (like you would a VM).
  • You can have versioned OSs using a differencing disk to create a parent child relationship between VHDs. This can be very disk space friendly if you manage many images.
What you'll need:
  • A system capable of running Hyper-V (Intel VT or AMD-V enabled)
  • Windows 7 installed
  • 15 GB of free disk space
  • The ISO for Windows Server 2008 R2
Note: In the examples below, I am doing everything on drive C: and assigning drive letter Q: to the VHD but you can use any drive that Windows 7 has available.

Preparing the VHD
First we'll need to create a VHD on the Windows 7 system using the DISKPART command:
1.       From the Start->All Programs->Accessories right-click the Command Prompt and select "Run as Administrator" - DISKPART will launch and you will be put into the DISKPART CLI shell.
2.       Let's have a look at what volumes DISKPART can see. Type:
list vol↵
Take note of what you see.
3.       To create a minimal size VHD that can grow to a maximum size of 15000MB type:
create vdisk file=c:\win2k8r2.vhd maximum=15000 type=expandable↵
4.       To set the focus of DISKPART to the newly created VHD type:
select vdisk file=c:\win2k8r2.vhd↵
5.       To attach the virtual disk to the system type:
attach vdisk↵
6.       We will need a primary partition within the virtual disk to make the VHD bootable; type:
create partition primary↵
7.       Although the partition can be formatted as part of the Windows Server installation, I prefer to do it now. To format the partition with the NTFS file system, type:
format fs=ntfs quick label="NewVHD"↵
8.       We don't really need to assign a drive letter to the VHD at this point since during the install of Windows Server, it will get a different drive letter anyway, but it makes it more convenient to investigate the VHD from Windows 7. Assign the drive letter Q: to the new partition by typing:
assign letter=q: ↵
9.       Let's have a look at what volumes DISKPART can see now.  Type:
list vol↵
You should see the new volume available with a size of 14GB.
10.   To exit the DISKPART shell type:
exit↵
11.   To exit the command  shell type:
exit↵
12.   Use Windows Explorer to see what size the file c:\win2k8r2 that contains the VHD is. It should be around 80MB. It will grow from here as we add contents to the volume.
13.   For fun use right click Computer from the Start Menu and you should see drive Q: mounted. You can check the properties of drive Q: by right clicking it.

Installing Windows Server
Now we are ready to install Windows Server 2008 R2 onto the newly formatted partition within the VHD. I'll provide general instructions here, just highlighting the differences from a standard installation.
1.       Boot from the Windows Server 2008 R2 ISO. At the screen that prompts you to select a language press SHIFT+F10 to access the WinPE console.
2.       To launch the DISKPART CLI shell:
diskpart↵
3.       Let's have a look at what volumes DISKPART can see. Type:
list vol↵
4.       To set the focus of DISKPART to the previously created VHD, type:
select vdisk file=c:\win2k8r2.vhd↵
5.       To attach the virtual disk to the system, type:
attach vdisk↵
6.       Let's have a look at what volumes DISKPART can see. Type:
list vol↵
7.       To exit the DISKPART shell, type:
exit↵
8.       To exit the WinPE shell, type:
exit↵
9.       Return to the Windows Server 2008 R2 setup and select Custom (advanced) as the installation type, not Upgrade.
10.   When prompted for the installation location, select the newly formatted volume that has the label NewVHD.
11.   Perform the remainder of the installation as usual.
12.   When you reboot you will notice that you get a boot menu allowing you to select the OS of your choice. Select Windows Server 2008 R2.
13.   Turn on the Hyper-V role.

Now you have a dual boot Windows 7 and Windows Server 2008 R2 system that can also run the Hyper-V role even though it is not installed in its own partition of a physical disk.
At this point, you could migrate your Windows 7 installation to a VHD so that both of your operating systems are booting from VHDs. If you choose this route, the Disk2vhd tool might prove useful.

You could also use the VHD that you just installed Windows Server into as a Hyper-V (or ESX) virtual machine (you will need to recreate or modify the BCD store first).
By the way, the size of the VHD you created will probably be around 6 GB when viewed from the Windows 7 instance.

31 August 2014

Database Seeding cmdlets

Get Database Copy StatusGet-MailboxDatabaseCopyStatus -Identity ‘EX10mbx01′ | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize

Status for all database copies on the Mailbox server EX10CHM10 by status
Get-MailboxDatabaseCopyStatus -Server EX10CHM01 | Sort-Object -Property Status| ft mailboxserver,DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy,ErrorMessage -AutoSize

UPDATE Seed a copy of a database named EX10mbx08 on EX10CHM01 using EX10CHM04 as the source Mailbox server for the seed
Update-MailboxDatabaseCopy -Identity EX10mbx01\EX10CHM02 -SourceServer EX10CHM01

UPDATE Seed a copy of a database named EX10mbx08 on EX10CHM01 using EX10CHM04 as the source Mailbox server for the seed (remove existing files)
Update-MailboxDatabaseCopy -Identity EX10mbx48\EX10CHM07 -sourceserver EX10CHM09 -DeleteExistingFiles

Update the Database using a source server and delete existing files
Update-MailboxDatabaseCopy -Identity EX10mbx02\EX10CHM10 -DeleteExistingFiles

Update ONLY the Database using a source server and delete existing files
Update-MailboxDatabaseCopy -Identity EX10mbx06\EX10CHM12 -SourceServer EX10CHM11 -DatabaseOnly -DeleteExistingFiles

Update Catalog Only
Update-MailboxDatabaseCopy -identity EX10mbx01\EX10CHM11 –CatalogOnly

Update Database Only without seeding the content index catalog
Update-MailboxDatabaseCopy -identity EX10mbx07\EX10CHM12 –Databaseonly

UPDATE the Catalog on EX10mbx08 on EX10CHM01 using EX10CHM04 as the source Mailbox server for the seed
Update-MailboxDatabaseCopy -Identity EX10mbx46\EX10CHM04 -SourceServer EX10CHM05 -catalogonly
Update-MailboxDatabaseCopy -Identity EX10mbx22\EX10CHM05 -DeleteExistingFiles

Resume all Copies in FailedandSuspended
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “FailedandSuspended”}| Resume-MailboxDatabaseCopy

Resume all Copies in Failed state on Server
Get-MailboxDatabase -server EX10CHM03| Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”}| Resume-MailboxDatabaseCopy

Resume Database Copy for all Databases located on Server
Get-MailboxDatabaseCopyStatus -Server EX10CHM07 | Resume-Mailboxdatabasecopy
Resume-MailboxDatabaseCopy -Identity EX10mbx01\EX10CHM09

Suspend Mailbox Database Copy
Suspend-MailboxDatabaseCopy -Identity EX10mbx01\EX10CHM11 -SuspendComment “Maintenance ” -Confirm:$False

Suspend all Copies in Failed state on Server
Get-MailboxDatabase -server EX10CHM10| Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”}| Suspend-MailboxDatabaseCopy
Get-MailboxDatabaseCopyStatus -Server EX10CHM01 | Suspend-MailboxDatabaseCopy

Add Mailbox Database Copy
Add-MailboxDatabaseCopy -Identity ‘EX10mbx01′ -MailboxServer ‘EX10CHM09′

Add Mailbox Database Copy (SEEDING POSTPONED)
Add-MailboxDatabaseCopy -Identity EX10mbx01 -MailboxServer EX10CHM11 -SeedingPostponed
MOVE ACTIVE DATABASE


Set Active Mailbox Database Copy
Move-ActiveMailboxDatabase -Identity ‘EX10mbx12′ -ActivateOnServer ‘EX10CHM04′ -MountDialOverride ‘None’

Set Active Mailbox Database Copy with failed Catalog
Move-ActiveMailboxDatabase -Identity ‘EX10mbx01′ -ActivateOnServer ‘EX10CHM01′ -MountDialOverride ‘None’ -SkipClientExperienceChecks

Remove Mailbox Database Copy
Remove-MailboxDatabaseCopy -Identity EX10MBX03\EX10CHM11 -Confirm:$False
Context Index


Disable Indexing on Mailbox Database
Set-MailboxDatabase “EX10MBX07″ -IndexEnabled $false

Enable Indexing on Mailbox Database
Set-MailboxDatabase “Mailbox Database EX10MBX03″ -IndexEnabled $true

Finding the passive Databases with Failed Index (can’t update the index on the active DB)
Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ? {$_.Status -ne “Mounted” –and $_.ContentIndexState -eq “Failed”} | ft -autosize

Fix the Passive databases with Failed Index
Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ? {$_.Status -ne “Mounted” –and $_.ContentIndexState -eq “Failed”} | Update-MailboxDatabaseCopy –CatalogOnly

Fix all Passive databases with Failed Index per Database
Get-MailboxDatabaseCopyStatus -identity EX10mbx01\* | ? {$_.Status -ne “Mounted” -and $_.ContentIndexState -eq “Failed”} | Update-MailboxDatabaseCopy -CatalogOnly

30 August 2014

Windows server 2012 task manager missing disk and network performance counters

I keep reading on some fora that this setting should not be used in a production envoironment, so try at your own risk or test first. 

Enabling Task manager Disk Performance Counters
 

  1. Ensure Task Manager is closed.
     
  2. Launch the Command Prompt using the "Run as Administrator" option.
     
  3. Enter the following at the Command Prompt:
     
    diskperf -Y
     
  4.  Hit Enter.
     
  5. Close the Command Prompt.
     
  6. Re-open the Task Manager

25 August 2014

Resolving DirectAccess Connectivity Issues

The NRPT

Direct Access utilizes a feature called the Name Resolution Policy Table (NRPT). This basically controls the way DirectAccess handles name resolution for specific Domains. Entries in the NRPT control where client machines look for name resolution on specific domains and allow finer control of what happens when client machines are utilizing DirectAccess for connectivity. For instance, you can utilize the NRPT to force client machines to look to external DNS servers for resolution on some hostnames or domain zones, while looking to internal DNS for everything else and vice versa. There are really only two ways to modify the NRPT, through the Registry (I don’t recommend modifying the NRPT through the registry), and through group Policy using the Name Resolution Policy node. Technet has some information on how to handle NRPT here: NRPT

The Problem with DirectAccess Failures

Usually when DirectAccess stops communicating, it stops working because the NRPT isn’t configured properly. If this happens, you may run into a situation where some systems are unable to ping domain controllers or other systems by using NetBIOS names or through FQDNs. This can be a huge problem, because if DirectAccess fails, systems will typically no longer be able to communicate with the Domain to retrieve corrected NRPT information, since this information is deployed via GPO.

Fixing the Communication Issue

If something causes your DirectAccess configuration on a client machine to corrupt or if Direct Access isn’t properly configured, it may be necessary to reset the NRPT on the client machine to fix the problem. The only way to modify the NRPT on a client machine is through the registry. If you’re experienced enough with DirectAccess, you may be able to resolve the issue directly in the registry. However, it is usually easier to just remove the existing NRPT entries on the client machine entirely. This has to be done in the registry at the following location: HKLM\Software\Policies\Microsoft\Windows NT\DNSClient\DNSPolicyConfig (Pictured below)

NRPTreg

Note the two entries there. Both are composed of DA-{GUID}. DA stands for DirectAccess. Remove any entries that have that DA- prefix and reboot. Once this is done, the system will begin communicating without DirectAccess and will have the ability to connect to the domain to retrieve new NRPT information if it is available.

After deleting the entries, you can either reboot or restart the DNS client service and do a gpupdate /force.

Source

09 July 2014

Set Active Directory user property's with Powershell

Need to edit a user property here's how:


To set the Dail-in property to deny access, you look for the corresponding value, in this case:
"msNPAllowDailin" which is set to TRUE.

In Powershell you type:set-ADUser username -Replace @{msnpallowdialin=$false}

Now when you look at the same value in the attribute editor it displays FALSE.


I haven't tried it but i guess everything that has a value can be changed or edited by the same command.
If you know some others, or disagree let me know.




Get system up time script and alternative ways

Save as a ps1 script, and run.

$computer = "computername"

$lastboottime = (Get-WmiObject -Class Win32_OperatingSystem -computername $computer).LastBootUpTime

$sysuptime = (Get-Date) – [System.Management.ManagementDateTimeconverter]::ToDateTime($lastboottime) 
  
Write-Host "$computer has been up for: " $sysuptime.days "days" $sysuptime.hours "hours" $sysuptime.minutes "minutes" $sysuptime.seconds "seconds" 

Outputs like:

PS D:\_DATA\Scripts> .\Uptime.ps1
computername has been up for:  71 days 4 hours 26 minutes 50 seconds

Alternatives:

1. Go to "Start" -> "Run".

2.  Write "CMD" and press on "Enter" key.

3. Write the command systeminfo | find "up time" and press on "Enter" key.

1. Go to "Start" -> "Run".

2.  Write "CMD" and press on "Enter" key.

3.  Write the command "net statistics server" and press on "Enter" key.


4.  The line that start with "Statistics since …" provides the time that the server was up from.

  •   The command "net stats srv" can be use instead.
Uptime.exe Tool Allows You to Estimate Server Availability with Windows NT 4.0 SP4 or Higher

Source

Alternate source