Download XML files with Powershell script

November 4, 2010

Let’s say we have a scenario where there is a need to download a huge amount of XML files from a central web server for whatever reason. This is an example but I had a situation very similar like this. That’s why I have created a PowerShell script which is able to do the job for me.

The script is created with a function  called Get-WebPageXMLS

function Get-WebPageXMLS($url, $folder)



Import-Module BitsTransfer

if (-not (Test-Path $folder)) { md $folder }

$ie = New-Object -COMObject InternetExplorer.Application


while ($ie.Busy) { Start-Sleep -Milliseconds 100 }

$xmls = $ie.document.getElementsByTagName(‘a’) | Select-Object -ExpandProperty href |

where { $_ -match “`.xml$” }


$xmls_n = $xmls.Length

if ($xmls_n -gt 0)


$i = 1

$webClient = new-object System.Net.WebClient # .NET class

$proxy = new-object System.Net.WebProxy “Ipaddress:port” # specify your proxy address and port

# replace your credential by your domain, username, and pasword in cause there is authentication

#$proxy.Credentials = New-Object System.Net.NetworkCredential (“Domain\UserName”, “Password”)


# specify a header if you want to check info in your logs on your proxy

$webClient.Headers.Add(“user-agent”, “Windows Powershell WebClient”)

#$b=Get-Credential #here you can uncomment this but comment the following



$webClient.credentials = new-object\username,”password”)

foreach ($lnk in $xmls)



$dst = “$folder\$($lnk.Split(‘/’)[-1])” 

$dn = $lnk.Split(‘/’)[1]

echo “Getting [$i/$xmls_n] $dn” 


#$webClient.Credentials = $b #uncomment if you use get-cridential

$webClient.DownloadFile($lnk, $dst)

#Start-BitsTransfer $lnk $dst -Prio High -Display $dn #uncomment if you wish to use bits transfer



} else { “Nothing to do – NO xml links found in $url” }



Get-WebPageXMLS http://Source                “c:\temp\destination”




With $b=Get-Cridential, if the site from where we download the files requires authentication, we can request user input for username and password. This is commented because we can put username and password directly in the script itself.

You can download the sccript here:












Error after publishing form with infopath in Sharepoint 2010

October 7, 2010
The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information, contact your server administrator.
1. Create the service application. Start powershell from sharepoint menu:
$srvap=New-SPSStateserviceApplication -name "State Service" – this is the creation of the service application.
New-SPStateServiceDatabase -name "StateServiceDb"-ServiceApplication $srvAp – the creation of the database for the application
New-SPStateServiceApplicationProxy -Name "State Service" -ServiceApplication $srvap -DefaultProxyGroup
After that you could verify from Sharepoint central administration console: Central Administration – > Application Management ->Manage Service Applicatios

Powershell script monitors particular service , tries to restart it and send email if it fails

August 27, 2010

This is a simple script which monitores w32time service. It can monitor avery service but i choose n that particular cause w32time. What is the genral idea:

1.We get an object service in variable $st. $comp is tha variable takes the hostname of the current computer.

2. If the service isn’t starter when the script runs it tries to start it three times implemented with help of a loop.

while (($st.Status -eq “Stopped”) -and ($i -lt 3)). You can get various methods and Properties from the object in variable $st with $st | get-member. One Property is the Status of the service $st.Status.

The Retries of the script is equalt to 3. $i -lt 3. It can be more then three. If for example $i -lt 8 the script will try 8 times to start the service before it fails.(if the service fails to start 8 times).

At last if the service is still in stopped state the script sends an email to notifyyou.

$st=Get-Service w32time
$comp=gc env:computername
while (($st.Status -eq “Stopped”) -and ($i -lt 3))
Start-Service w32time
$st=Get-Service w32time


if($st.Status -eq “Stopped”)
$smtpclient=New-Object system.Net.Mail.SmtpClient
$mailmessage=New-Object system.Net.Mail.MailMessage
$mailmessage.Subject=”Please Check the service “+$st.Name+” on machine name “+$comp+” !!!!!!!!!!!”
$mailmessage.Headers.Add(“message-id”, “<3BD50098E401463AA228377848493927-1>”)

So you can save the file with ps1 extension. For Example: str-service.ps1. After that you can create bat file with the following line Powershell -command “& {C:\Scripts\str-service.ps1 }”. The bat file can be add in Shedule tasks after that with appropriate schedule.

Hyper-v Server R2 Remote management in Workgroup

August 27, 2010

Here I tried to make clear guide how to manage Windows Server 2008 R2 with Hype-V role installed  or Hyper-V server from Windows 7 machine while both Win 7 and Hyper-V server are in workgroup scenario. You can find detailed post here:

What I do in this post is to make some basic guide with steps 1,2 etc.

1. Install Hyper-V Server R2. Nothing strange just as a usual Windows Server 2008 R2

2. Create two identical users on both machines with the same password. For example:

a. On Win 7 machine 

b. On Hyper-V Server issue a command

net user Deen * /add

In my cause I add Deen in local administrators group on both machines but isn’t necessary to be in local administrators group on the Server.

3. Issue a command in a Hyper-V server again

Netsh advfirewall firewall set rule group=”Windows Management Instrumentation (WMI)” new enable=yes

Net localgroup “Distributed COM Users” /add  HV-Server\Deen

(HV-Server is the name of HyperV Server machine)

4. Right click on the computer management console (top) and select connect to another computer.

Then connect to Hyper-V Server

You have to set two times the security. Once for Root\CIMV2 and then for the ROOT\virtualization.

For CIMv2 only the permission Enable Account is sufficient.

For \Root Virtualization enable account and remote enable is enough.

You can add the requested permissions in the whole root three but is less secure.

5. Work with AZman on Hyper-V Server.

Net use * \\HV-Server\c$

After that you have to load one xml file from the server.

Navigate to mapped drive  \ProgramData\Microsoft\Windows\Hyper-V directory on the Hyper-V server and add Deen to Role Assignments Administrator container.

6. Give the following permissions on the Win 7 machine.

VMware Tools may not Upgrade on a Windows 2008 guest operating system

July 15, 2010

There is an issue upgrading Vmware Tools on Windows Server 2008 guest operating system. The host was Vmware ESX 4.x. There is a KB article from Vmware Basically what has happened is that Vmware tools refused to remove itself and in the middle of removing procedure the tools requested the source which is different from the source mounted in the CD drive.

The solution of the problem is to force uninstall the tools because the old package is no longer available.

Navigate to CD drive and locate setup.exe executable file from Vmware tools installation path. Open cmd from start -> Run and navigate to the setup.exe file. Issue the command setup /c.  It will forece remove vmware tools and all registry settings. Then Install the new tools with the same setup.exe without any switches.

SCOM 2007 R2 agents stop talking after their installation with SCOM Server

April 11, 2010
I have Scom 2007 R2 server installed in one domain enviroment and a couple agents on windows 2003 and windows server 2008 (not R2). The other scenario i have is that i deployed SCOM Gateway in the internet with the other non-trusted domain with certificate trusted communication. Everything worked fine until the moment i tried to install agents in the other domain with two way forest wide trust. The servers there were Windows Server 2008 R2. So the SCOM R2 server was in Domain A and domain A had two way forest trust with a domain B where agents should be. The only difference was that all servers in the domain B were Server 2008 R2. After discovery and agent installation all agents were in "Not Monitored" state.
The errors from event log of the monitored servers were:
Event ID:      20070
The OpsMgr Connector connected to "SCOM R2 FQDN" but the connection was closed immediately after authentication occurred.  The most likely cause of this error is that the agent is not authorized to communicate with the server, or the server has not received configuration.  Check the event log on the server for the presence of 20000 events, indicating that agents which are not approved are attempting to connect.
Event ID:      21016
OpsMgr was unable to set up a communications channel to "SCOM R2 FQDN" and there are no failover hosts.  Communication will resume when "SCOM R2 FQDN" is available and communication from this computer is allowed.
There are many posts concerning communications between SCOM R2 and gateway server and them cerificates but the solution in this situation is updating management packs.

1. Open the SCOM Console

2. Go to “Administration” section

3. Right click on “Management Packs” and select “Import Management Packs”

4. Click Add and select “Add from Catalog…”

5. In View: drop down menu select “Updates available for installed management packs” and click “Search” button
Then update management packs
After i update them i restart "System center management" service on the monitored machines and they start to communicate with SCOM 2007 R2 server.

Microsoft DPM Server does not remove old recovery points (after expiration of retention period)

April 11, 2010



I have been using DPM of about 6 months until now. The story is that i have of about 4 DPM 2007 production servers. I have various protection groups which protects databases,file system, system state e.t.c. 

After creation of that protection groups everything seemed fine. But after a month ago I kept running out of free space of recovery point volumes for every member of the particular protection group. What I’ve done is that I had some free space on my storage which is used by DPM and every time I increased free space of that particular member. For example I have protection group for database server SRV1 which includes three protected databases db1, db2, db3. I was keeping recovery points for 7 days. Finally I discovered that there are recovery points on Recovery tab of DPM for the whole month. It wasn’t keeping them only for 7 days. The solution I found is to delete the old recovery points manually through PowerShell.  Although there are many sources for that, here is my guide how to do delete them.

1.List of dpm protection groups
get-protectiongroup Srv1

2.Store the output in variable $pglist

$pglist=get-protectiongroup Srv1
output only to count 0,1,2,3,4…

Foreach($pg in $pgList){write-host($pg.FriendlyName)}  // this is only for to see display of members

so you should count members of the protection group always from 0 after that 1,2,3 e.t.c

Db1  -count 0

DB2 -count 1

DB3 -count 2

the statement above will print out the list of protection group in your DPM
server. the first protection group should be referred to $pglist[0], the second one
should be referred to as $pglist[1] and so on

3.Get the source of protected group

$dslist = get-datasource($pglist[X]) for example 6

check to see if you have more than one data source by issuing this command:
write-host $ if you are not getting any output this means that there are multiply data source. For example in DB1 i have multible data sources every 15 minutes because i’ve made synchronization with consistency check every 15 minutes. If this is the cause you need to select which one you are going to use.

foreach($ds in $dslist){write-host $}

master -1

model -2

DB1 -3

For Example i want to delete recovery points from DB1 which is count 3.

4. Get recoverypoints

get-recoverypoint $dslist[3]       //only to verify 

The output is something like:

DB1 12-1-2010 1:05:09   SRV1\DB1… Disk //count 0
DB1 13-1-2010 1:05:41   SRV1\DB1… Disk //count1
DB1 14-1-2010 1:05:48   SRV1\DB1… Disk
DB1 15-1-2010 11:55:40  SRV1\DB1… Disk
DB1 15-1-2010 11:59:42  SRV1\DB1… Disk
DB1 16-1-2010 1:06:43   SRV1\DB1… Disk
DB1 17-1-2010 1:05:28   SRV1\DB1… Disk
5. Optional step for review only

$rplist=get-recoverypoint $dslist[x] example 0
foreach($rp in $rplist){write-host $rp.representedpointintime}

12-1-2010 1:05:09 //count 0
13-1-2010 1:05:41 //count 1
14-1-2010 1:05:48 //count2
15-1-2010 11:55:40
15-1-2010 11:59:42

5.Remove recovery points
remove-recoverypoint -recoverypoint $rplist[x]  //0,1,2 and so on

Here is the whole simple script:

get-protectiongroup SRV1
$pglist=get-protectiongroup SRV1
Foreach($pg in $pgList){write-host($pg.FriendlyName)}
$dslist = get-datasource($pglist[1])
write-host $
foreach($ds in $dslist){write-host $} //count which recovery point you should delete from 0,1,2
get-recoverypoint $dslist[4]
$rplist=get-recoverypoint $dslist[4]
foreach($rp in $rplist){write-host $rp.representedpointintime}
remove-recoverypoint -recoverypoint $rplist[0]

Here is the othe approach. If  write-host $ outputs some result here is the steps need to be taken.

write-host $

systemstate – this is an example

$rplist=get-recoverypoint $dslist

foreach($rp in $rplist) {write-host $rp.representendpointintime}

remove-recoverypoint -recoverypoint $rplist[0]  //and $rplist[1],2 and so on

or if it refjuses to delete recovery points

remove-recoverypoint -recoverypoint $rplist[0] -ForceDeletion


April 11, 2010

Deleting old “Internet Newsgroups” Public Folder which prevents Exchange 2007 to be uninstalled

March 31, 2010

There was migration from Exchange 2003 to Exchange 2007. After some time when Exchange 2010 appeared i’ve migrated half of my enviroment to Exchange 2010. After that i moved all mailboxes to the new exchange server. After that it came time for uninstalling the old Exchange 2007 server. Here came the fuirst problem. I had to move all replications of public folders to other exchange servers. It’s not a heavy task and there is powershell script:

.\MoveAllReplicas.ps1 -Server ExchOld2007  -NewServer Exch2010New.

After that i’ve need to remove all public folders on the old Exchange 2007 server.

You can stop replication of Public folders totally that way:

Get-PublicFolder -server ExchOld2007  “\” -Recurse -ResultSize:Unlimited | Remove-PublicFolder -server ExchOld2007 -Recurse -ErrorAction:SilentlyContinue

When i try uninstalling Exchange Server 2007 again i faced the following new error:

Uninstall cannot proceed. Database ‘Public Folder Database’: The public folder database specified contains folder replicas. Before deleting the public folder database, remove the folders or move the replicas to another public folder database.

After that i went to the pulic folders GUI console it appears Internet Newsgroups Public Folder. When i tried to delet it there is another error:

Microsoft Exchange Error
Action ‘Remove’ could not be performed on object ‘Internet Newsgroups’.

Internet Newsgroups
Cannot delete the object ‘\Internet Newsgroups’. Please make sure that you specified the correct identity

and that you have the correct permissions to delete it.

MapiExceptionPartialCompletion: Unable to delete folder. (hr=0x40680, ec=0)
Diagnostic context:

So the solution here is deleting that particular folder from ADSIEDIT.MSC

1. Open Adsiedit.msc from run command
2. Navigate to your configuration container

3. Expand to services, Microsoft Exchange, your organization name, administrative groups,Exchange Administrative Group, servers, locate your MailBox Server, expand it and then locate information store.
4. Locate particular storage group where is public folder store. On the right pane, delete the public folder store (storage group).

After that uninstallation continue fluently.

Install Windows Server 2008as backup feature on Server Core

March 19, 2010

What do you need to backup Server 2008 Core computer ? Yes there is a feature which makes VSS backups.

start /w ocsetup WindowsServerBackup – this installs windows server backup feature.

After that you can start backing up using cmd tool called wbadmin. Here is one example backing up D: to shared

network folder:

wbadmin start backup -backuptarget:\\Server02\BackupShare  -include:d: