Waclaw Chrabaszcz
... there is no spoon ...

PowerShell – duplicated files in Windows Media Player library

Holiday! .. But why it's raining. Let's cleanup some duplicated MP3s. Maybe the rain will stop in the meantime.

For sure this code is not optimized, and I am not recommending anyone to use it. If you uncomment move actions you can reduce number of duplicated media files in your Windows Media Player library.

You can consider it as an example how to access and browse WMP using PowerShell.

 

$wmp = New-object –COM WMPlayer.OCX
$playlist = $wmp.mediaCollection.getAll()
$i=1
do {
if ($playlist.item($i).sourceURL -like "*.mp3")
{
if ($playlist.item($i).name -eq $playlist.item($i-1).name)
{
write-host "n-1 : " $playlist.item($i-1).sourceURL
write-host $playlist.item($i).name " : " $playlist.item($i).sourceURL
if ($playlist.item($i).sourceURL.tostring().length -gt $playlist.item($i-1).sourceURL.tostring().length )
{
Write-Host -ForegroundColor yellow "moving " $playlist.item($i).sourceURL
#Move-Item $playlist.item($i).sourceURL "c:\output"
}
else
{
Write-Host -ForegroundColor red "moving " $playlist.item($i-1).sourceURL
#Move-Item $playlist.item($i-1).sourceURL "c:\output"
}
}
}
$i++
}
while ($i -le ($playlist.count -1))

Ahh .. A quick description, you've got media files in many folders. The script checks WMP library and in case of conflict wins the file with shorter URLpath. To move files uncomment #Move-Item. And let WMP rebuild library before next script run. It may take up to 3 days.



Server 2012 GUI – to be or not to be …

That's the question J

This quick post is inspired by one of feedbacks.

To enter into PowerShell just type powershell in CMD

To make Server 2012 core server:

Powershell
Uninstall-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra
Shutdown –r

 

To restore server's GUI

 

Powershell
Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra
Shutdown –r

Voila !

P.S. Of course it not works for 2008



Server 2012R2 – PowerShell Web Access

Haha … Sometimes I'm joking that there is nothing worse than Linux fanboi imprisoned in Windows engineer's body. Maybe someday I will start blogging about my noob's experiences. However let's stick to the point. Sometimes the easiest solutions are the best. After couple of tries how to reach left pocket using right hand I'm going to follow easy path. Today's plan is very easy, I'm going to take advantage of Server 2012 and install Web gateway to PowerShell console. After that I would be able execute PoSH from any device including Linux.

Install-WindowsFeature –Name WindowsPowerShellWebAccess –IncludeManagementTools
Install-PswaWebApplication –UseTestCertificate
Add-PswaAuthorizationRule –UserName * -ComputerName * -ConfigurationName *

 

Let's test it …

 



SQL 2012 – How to setup AlwaysOn cluster

As an application administrator, or transition engineer I need to store my data on some sort of database. Because SQL itself is not my primary focus I rather prefer "I don't care" solutions. It not means I don't care whether database is running or not. It mean I don't have enough time to become an expert in additional area to setup and understanding e.g. Log Shipping. What's more, it's not my problem only. I'll setup some SQL HA solution and walk away, whereas poor WinAdmin will RDP there day by day with heart palpitations.

Since SQL 2005 we've got two user friendly solutions, unfortunately each has a weak point.

  • SQL Cluster –needs a shared storage, in most cases expensive Enterprise class Disk array. And when we talk about DR scenario, we have to switch to remote location, as a result complexity and difficulty are growing very fast.
  • SQL Mirroring – for some reason not liked by many SQL admins (to be honest I would like to know why), and the weak point is limit to two nodes only.

Now with this background we can start to talk about SQL 2012 AlwaysOn. AlwaysOn thanks to mixing SQL and Server technologies removes mentioned limitations.

  • We can build cluster with more than two nodes – I think Windows Cluster (2008/1012) sets limit of nodes. In most of business cases you won't need more than 4-5 nodes. Only two of them works synchronously and can be failover automatically (HA), other are feed with data asynchronously (DR) and should be failed over manually. Good news, to not waist resources (and licenses) async nodes are not passive and you can use them for read only proposes e.g. reporting. Of course it can remove lot of load from primary production database.
  • We don't need any shared storage, what is huge advantage when we talk about Disaster Recovery scenarios.
  • My poor WinAdmin has his lovely right click tool J

In this exercise we will build typical SQL 2012 AlwaysOn Solution:

  • SQL-1 and SQL-2 will be High Availability pair in primary datacenter
  • SQL-2 will Disaster Recover in secondary DC, we will use SQL-3 for reporting proposes

Let's do it!

In first step on each node we will install cluster feature:

  1. In the second we will build Windows Custer using all nodes




    Read it carefully




    in production I would recommend you to use static IP address
  2. Now you can prepare each SQL instance for clustering

Make sure that both Replication Partners are added into each SQL users:

(an example for SQL-1)

use [master]
GO
CREATE LOGIN [TESTDOMAIN\SQL-2$] FROM WINDOWS
CREATE LOGIN [TESTDOMAIN\SQL-3$] FROM WINDOWS
GO
GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [TESTDOMAIN\SQL-2$]
GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [TESTDOMAIN\SQL-3$]
GO

  1. We will need to make full backup of our database for initial replication. Use \\UNC\path\

  2. Eventually we can enable AlwaysOn on the database






   

   

   

Voila !



Easter egg – OMG^2 the true PowerShell in bash window

Let's continue this crazy experiment. More or less it should works on any distro in my case it is Ubuntu 13.

The idea is to use wine (Wine Is Not an Emulator J) to install Powershell 2.0 for Windows XP. Wine can emulate W7 or W8 however it refuses to install .MSU packages. To reach our goal we will need to use experimental wine 1.7 or above and EXE file so …

For the science!!!

sudo add-apt-repository ppa:ubuntu-wine/ppa
sudo apt-get update
sudo apt-get install wine1.7 winetricks
wget http://kegel.com/wine/winetricks
bash winetricks -q msxml3 dotnet35sp1
bash winetricks lucida
taskset -c 0 bash winetricks windowscodecs
wget -O ~/.cache/winetricks/WindowsXP-KB968930-x86-ENG/WindowsXP-KB968930-x86-ENG.exe http://download.microsoft.com/download/E/C/E/ECE99583-2003-455D-B681-68DB610B44A4/WindowsXP-KB968930-x86-ENG.exe
cd '~/.cache/winetricks/WindowsXP-KB968930-x86-ENG'
wine ./WindowsXP-KB968930-x86-ENG.exe


wine powershell

Happy Easter!



How to install XenApp 7.5

Ha!Ha! XenApp is back! ... Not exactly ... For me XenApp that's IMA architecture, here we have XenDesktop's FMA. Is it better, that's very good question. For me it is just different. Of course I like Broker-Agent concept, but where's my QFARM command? Based of rumors, not confirmed so far by myself, sessions prelaunching, support for retired Citrix streaming and of course Web Interface is back. Let's check it. Hmm .. Looking into official documentation it is not so sweet, sessions prelaunching for sure has been removed.

http://support.citrix.com/proddocs/topic/xenapp-xendesktop-75/cds-overview-features-not-in-this-release.html

 

To install Delivery Controller execute:

ServerManagerCMD -Install NET-Framework-Core
"D:\x64\XenDesktop Setup\XenDesktopServerSetup.exe" /xenapp /noreboot /quiet /configure_firewall /components CONTROLLER,DESKTOPSTUDIO,DESKTOPDIRECTOR,LICENSESERVER

 

To install a worker:

ServerManagerCMD -Install NET-Framework-Core
"D:\x64\XenDesktop Setup\XenDesktopVDAsetup.exe" /quiet /components VDA,PLUGINS /controllers XenApp75-1.testdomain.net /enable_remote_assistance /ENABLE_REAL_TIME_TRANSPORT /enable_hdx_ports /nodesktopexperience

 

After XenDesktop's style Site deployment everything is set and ready … but http://www.youtube.com/watch?v=DkDSP7sdLG8

I'll stay with the true name and features of this product, it is called XenDesktop 7.5, and I really like it …. btw if you agree with me just remove /xenapp from the command line J

 



SCOM 2012 R2 – How to put servers into Maintenece mode using PowerShell

In more or less ITIL's world you have to monitor availability and performance of your servers. However from time to time you need to apply approved changes, what means temporary unavailability or performance degradation. When we talk about Worldwide organizations, in many cases it is really hard to inform everyone about upcoming changes. Sometimes you don't want to inform anyone, you just don't want to wake up your colleagues at 2:00 AM their local time. So to apply the change in elegant way let's put affected boxes into maintenance mode, SCOM won't bother anyone with fake alarms. To not spend all day on SCOM console, let's use PowerShell for this task.

Import-Module -name OperationsManager
$servers = (`
'dc.TESTDOMAIN.net',`
'SQL-1.testdomain.NET'`
)

$Time = ((Get-Date).AddMinutes(30))
$comment = "Change-997: Applying MS hotfixes"
$reason = "ApplicationInstallation"
<# -Reason Valid values are: PlannedOther,
UnplannedOther, PlannedHardwareMaintenance, UnplannedHardwareMaintenance, PlannedHardwareInstallation,
UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration, UnplannedOperatingSystemReconfiguration,
PlannedApplicationMaintenance, ApplicationInstallation, ApplicationUnresponsive, ApplicationUnstable,
SecurityIssue, LossOfNetworkConnectivity.
#>
foreach ($server in $servers)
{
$Instance = Get-SCOMClassInstance -Name $server.ToUpper()
Write-Host $Instance
Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Reason $reason -Comment $comment
}

If you'll have problem with comma formatting try this way:

$servers = ('dc.TESTDOMAIN.net','SQL-1.testdomain.NET')



Windows 8.1 – God bless the miracast

As happy owner of the most sexy ultrabook Samsung NX900 i5 - I always wanted to use my TV as secondary wireless monitor. Why? Number one: for watching movies, number two: as additional display when I work from home. Today's post will be much more related to the lifestyle, than IT technology. However this setup gave me much more excitement than deployment of hundreds stateless VDIs.

Many people still asks themselves: "why should I migrate into Windows 8.1". In my case the answer is Hyper-V and Miracast. Hyper-V because it is easy, free, and efficient hypervisor. Of course if someone love VMware Player or VirtualBox he can stay with it. But personally, I shy a bit, that … as declared and certified Microsoft engineer I know WMware PowerCLI better than Hyper-V PowerShell commandlets . So, good bye Hyper-V GUI, since now everything what I do will be implemented via PowerShell.

But … let's stick to the point.

Consider this post as usecase, not the endorsement of anything in particular. So, we've got i5 Samsung NX900 laptop with Intel 3000 GPU, declared by manufacturer WIDI support and brand new Samsung F6640 TV set.

A little background

WIFI direct - it is a very young streaming standard, your TV set have to support it, otherwise you will need to buy any WIDI or Miracast receiver

Miracast – it is a streaming technology originally designed for Android devices, and in my opinion, it is one step from becoming global standard. If I understood correctly what I read, WIFI direct covers/includes Miracast

Intel WIDI - it is an old PC streaming technology, based on Intel GPU, NIC, and Audio components – your laptop must support it. Since version 3.5 Intel WIDI supports/emulates Miracast streaming.

Windows 8.1 brings out of box support for Miracast

After few failed tries on Windows 7 I decided to upgrade my laptop to 8.1, including the installation of all hotfixes and drivers. During long hours of tests I found that for WIDI it is very important to have PROPER graphics driver, WIDI version, (WTF !!!) Network adapter driver and Audio device driver. The easiest way to reach it is to install Intel WIDI update tool: http://supportkb.intel.com/wireless/wireless-display/templates/selfservice/intelwidi/#portal/1026/article/16168 . It will download and install all required components for you. My current configuration:

Get-WmiObject -Class Win32_product|where { $_.Name -like "*Intel*"} | Format-Table Name,Version

Name Version
---- -------
Intel(R) WiDi 4.3.3.0
System Requirements Lab for Intel 4.5.22.0
Intel(R) PRO/Wireless Driver 16.07.0000.0730
Intel(R) PROSet/Wireless Software for Bluetooth(R) Technology 2.6.1209.0268
Intel® PROSet/Wireless WiFi Software 16.7.0.0297
Intel(R) Update Manager 1.6.0.56
Intel® Trusted Connect Service Client 1.24.388.1

My apologies, but I'm not going to break original PowerShell formatting. Once you install all required drivers, reboot your laptop and in the meantime make sure that you have the most recent firmware installed on your TV. Don't forget to connect your TV to your home network. Windows 8.1 should install couple of hotfixes, and after the reboot you'll be able to discover your TV set in WIDI software as well as device in your Settings | Change PC settings.

I noticed about 1 second delay on streamed screen, so for gaming you'll still need to relay on HDMI cable, in any other scenarios it works perfect.

Maybe my method is not efficient but for sure it works …



Active Directory – How to promote Server 2012 R2 to DC and even more using PowerShell magic

It will be quick post, I have limited access to the Internet.

Today we are going to promote Windows 2012 to Domain controller and move some unique roles to it. It can be handy in DR scenario, or when we are going to raise domain functional level. It is very easy task, so to make some fun I'm not going to touch a GUI.

Prepare AD forest for Server 2012 if it is needed. Of course as a Schema Admin, of course it is one way ticket, so think twice before you do anything.
Don't forget about backing up your AD. It is recommended to execute it on the Schema Master server

{your Server 2012 R2 cd installation media}\support\adprep\adprep /forestprep

If you are sure that you are sure type c and hit Enter

After that we can switch to our destination Server 2012 R2,

Add-WindowsFeature AD-Domain-Services
Import-Module ADDSDeployment
$pwd = convertto-securestring "P@ssW0rD!" -asplaintext –force
Install-ADDSDomainController –DomainName "testdomain.net" –SaveModeAdministratorPassword $pwd –Force

Optionally after the reboot

Move-ADDirectoryServerOperationMasterRole –Identity DC2012 -OperationMasterRole PDCEmulator,SchemaMaster,DomainNamingMaster,InfrastructureMaster,RIDmaster –Force –Confirm:$false

Where DC2012 is a hostname of the new domain controller



OMG!!! A PowerSHELL within the bash console!

Each year during last days of the calendar year most of corporations enters into change freeze mode. During these days IT pros have to do … nothing J ! This is an example, how these stories usually ends ..

I don't like to wear a hat, especially red, so my favorite penguin is named Ubuntu. I found nice .DEB package named winexe

http://download.opensuse.org/repositories/home:/ahajda:/winexe/xUbuntu_12.10/i386/

After the installation we have access to new command, let's test how it works in "practice"

Winexe –interactive=1 –user testdomain/Administrator –password Password1 //scom.testdomain.net cmd.exe
powershell get-service –displayname System*

At this point of time I cannot execute PowerShell directly, perhaps I will need to lower security settings on the Windows box, I have few days to play cats and mice game with it ..

Yes I know it not make any sense. But it is sexy, isn't it?

Happy and silent Christmas with best friends and families! Let be a peace between Linux&Windows, XenDesktop&VMwareView, Hyper-V&ESXi, EMC&NetApp, PowerShell&bash, ASP.NET&PHP … My best wishes to every of You! Let the New Year bring us new challenges, opportunities and a lot of luck in professional and personal lives!