Adding features in Windows 2008 Server R2 in Server Manager programmatically - windows

I am writing a program that needs .NET to run.
When I run it on Windows 2008 Server R2 it fails upon .NET 3.5 installation.
This is because in this version of Windows you can only install .NET 3.5 via Server Manager (or Role Manager).
I was wondering if there is a way to do it programmatically?
I searched the web and found that maybe I could use PowerShell or WMI. I hoped that someone here could verify that that's the way to go, and if not, point me in the right direction.
UPDATE:
From further investigation I found that using WMIs Win32_ServerFeature_ID class I can enumerate the existing features. But I cannot find any explanation as to how to add a new feature.
Help very much needed.
Thanks.

This can be done by invoking the dism command programmatically:
dism /Online /Enable-Feature:NetFx3
I would be interested in hearing any solutions that don't require a shell-out though.

The Win32_ServerFeature wmi class does not expose any method to add or remove a Windows server feature, only is intended for list the features installed. and as far I know there is not a WMI class to do this task. the option which I can recomend you is use these PowerShell Cmdlets
Add-WindowsFeature
Get-WindowsFeature
Remove-WindowsFeature

I know this reply is in reference to Windows 7, but for anyone looking, there is an extension that works for Windows 7. PowerShell module to Add/Remove Windows 7 features

We use PowerShell to automate server setup, you'll find it will do what you like very nicely. For the feature you're looking at the script would look something like this:
Import-Module ServerManager
$netFx = Get-WindowsFeature -Name AS-NET-Framework
if ($netFx -eq $null)
{
Add-WindowsFeature AS-NET-Framework
}
This script will be runnable via your application's installation process... probably. I've run PowerShell from Windows Installer custom actions and that's (in my experience) the toughest case.

Related

How to export SCCM 2012 R2 Aplication in c# or VB.net?

I want to export an application (not a package) for our SCCM test server to our production server.
I know i can do it with the powershell cmdlet 'Export-CMApplication' but i need to use 2 different credentials to access the test server and the production server and i can't pass the credential to this cmdlet.
I think i can make it with the dll 'Microsoft.ConfigurationManagement.ApplicationManagement' but i don't find any relevant information as to how to do it.
Can someone help me please ?
I did not look at the VB or C# cmdlet yet, sure there is a way.
But just sticking to Powershell and command line, looking here.
Did you try?
runas /profile /user:otherdomain\testuser “powershell.exe \”C:\somepath\powershell\script.ps1”\”
Can also be unattended, but that is not very secure.

cannot create windows cluster file share using powershell/wmi

The win32_clustershare does not have a Create method on win2008r2? How does one create file shares using ideally wmi?
I thought the Win32_ClusterShare class was read only, but could be mistaken.
To do it without WMI, you can use the cmdlets in the FailoverClusters module, but you'll probably have to install Windows Management Framework 3 or (preferably) WMF 4 on your Windows 2008 R2 machine since these cmdlets aren't available in Powershell 2.0.
With 3.0+, you should be able to use Add-ClusterResource and the related cmdlets.
Apparently the win32_clustershare.create does not work as expected and is broken. Previously this class was absent altogether from windows as indicated here-
http://support.microsoft.com/kb/971403
Apparently Using win32_share does the needful even for clusters. I confirmed in HKLM\Cluster\Resources that the share is properly registered in the cluster.
Apparently windows is able to determine that the share upon creation is properly associated with a clustered disk.
I know I am not calling the win32_clustershare wrong, because I confirmed that the parameters are identical across the 2 wmi classes.
This is evident in inspecting both
(get-cimclass -ClassName win32_share).CimClassMethods["Create"].Parameters |fl *
(get-cimclass -ClassName win32_clustershare).CimClassMethods["Create"].Parameters |fl *
If you are using Windows Server 2012 R2/Windows 8.1, you can use the new and much improved SMB PowerShell modules. Have a look at https://technet.microsoft.com/en-us/library/jj635726(v=wps.630).aspx and http://windowsitpro.com/powershell/managing-file-shares-windows-powershell

Interoperability of PowerShell

I am distributing an installer and it will open and run a PowerShell script. The installer will be used by people who have Windows XP and up.
Am I guaranteed that this script will run/execute on all these versions of Windows? I'm looking for the similar Cross-Windows-Platform interoperability that Batch files provide.
I've heard of the error: "File cannot be loaded because the execution of scripts is disabled on this system" what can I do in this scenario? If a user has disabled scripts does that mean I will need to use a different language(maybe just Batch)?
The error you're quoting is due to the default execution policy of PowerShell when it's installed. The message indicates that PowerShell is installed,but by default it's very restricted about what scripts may run for security purposes.
See this article for more on the subject.
If you're going to use PowerShell in your installer, make it part of the system requirements for your software. I can't find anything that definitively says you can redistribute PowerShell with your application, but it's worth asking Microsoft about it.
PowerShell isn't "guaranteed" to be on any desktop OS older than Win7, but it is distributed via Microsoft Update and there's no compelling reason for users to not have it installed.
If you manage this environment, then make sure that powershell is installed on the XP workstations before deploying the script. There is also the option of configuring group policy for powershell to enable script execution and what type of scripts to allow, but that's outside the scope of this question.
If you don't go the group policy route, and instead want to just run the script directly, then in your installer, call powershell.exe directly and pass in the following parameters:
powershell.exe -executionpolicy bypass -file \\path\to\script
The script path doesn't have to be a unc path if it's local, that was just an example.
No, PowerShell scripts are not guaranteed to run on Windows XP or Windows Server 2003. Although PowerShell is available for these platforms, it's not installed by default.
No, PowerShell scripts may not work, because the PowerShell isn't pre-installed on Win XP/2003.
It is included in the Management Framework for XP/2003.
For me, I suggest to use the .bat instead.

Install windows service without using InstallUtil or Setup Installation

I would like to send a windows service program to our client that does not have InstallUtil (no rights to distribute) and this one will be multiple installations in the same machine.
I found something at this point: Inno Setup for Windows service?
But I am not clear how to:
add the InnoSetup script and where to add this script?
For the if and else: System.Environment.UserInteractive? if a service is not installed, then it will be going inside this if?
Thanks in advance.
I have provided a step-by-step solution for how to add command-line install/uninstall to your Windows service using C#. This solution lets you avoid requiring the use of InstallUtil.
How to make a .NET Windows Service start right after the installation?
You need to add an installer to your service setup project, and a custom action. This article will get you started.

How to admin a remote Windows Server with a command line interface?

When I was a Linux admin I could do anything from the SSH command line. Now, as a Windows admin, I have to deal with the Windows Remote Desktop graphical interface, which I found to be inefective (slow) and hard to automate tasks in it.
a) Can I connect to a Windows Server through SSH or any encrypted connection with command line interface?
b) If yes can I do ANY administrative task?
Examples:
create a new virtual folder in IIS
setup firewall ports
restart services
change user policies
start desktop applications
I know about the existence of Windows PowerShell 2.0 Remoting, but I don't know if it fullfills all conditions above
My conclusion so far: from Windows PowerShell can do MOST but not ALL administrative tasks. And I still don't know if Windows PowerShell 2.0 Remoting uses an encrypted connection.
PowerShell is what you're looking for. It is primarily targetted at system administration (although it's fanastic as a programmer's shell, too).
PowerShell v2 remoting is based on Windows Remote Management. See http://msdn.microsoft.com/en-us/library/aa384426(VS.85).aspx. It includes facilities for ecryption and authentication, as you'd expect.
PowerShell includes cmdlets that let you do a lot of everyday tasks. Microsoft server applications (IIS, Exchange, etc.) either have or are building PowerShell cmdlets to administer them. PowerShell's WMI support is excellent, giving you a lot of machine administration power. PowerShell can talk to .NET directly, which lets you go further than built-in facilities when needed. And writing C# for PowerShell to call works out cleanly, too.
You asked for a command line interface, but don't think that you're restricted to the ancient and crufty Windows Console subsystem. PowerShell v2 includes a new GUI interactive shell / script editor, with colorization and debugging. It's sweet.
You can also try http://sshwindows.sourceforge.net/
I don't have personal experience with it but it looks promising.
Did you consider Google? (looks like you edited your question. You now no longer ask if the example tasks can be achieved using PowerShell)
Powershell snap-in for IIS 7
Restart-Service
Group policies
etc...
Sorry for not answering your question. I was in a similar situation.
I gave up to do all tasks on the windows shell
Instead I do use the shell for some tasks, but I am also using rdesktop (through ssh) and I put icons for the most important gui admin tools on the windows quicklaunch.
I gave up making windows feel like unix because it never will.
alternatively try to download and install eurysco to use the following features that is based on another logic...
1.create a new virtual folder in IIS (from eurysco commandline to launch vbs or powershell script)
2.setup firewall ports (from eurysco commandline to launch netsh.exe advfirewall)
3.restart services (from eurysco service control)
4.change user policies (from eurysco system registry or commandline to launch powershell script)
5.start desktop applications (from eurysco commandline to launch powershell script)
http://www.eurysco.com/features

Resources