Thursday, September 10, 2015

How to - Adding AD Group to local computer Group using Group Policy

Last month I had written article on how to copy files on computers using Group Policy. This time I will be showing how to add AD Group in local machines Group, Same process can be used to create new local group. This can help to bring servers and computers in compliance. At this point I Have create one Group in AD called System Server_Administrators and I will be add this AD group vCloud.lab\server_Administrators to local machines Administrators group.
 

As a start below is the summary, In my Active Directory Users and Computers console I created OU called vCloud.lab and all my Computer accounts are in it under Computers OU. With correct step you can achieve great automation through Group Policy.
Here open Group Policy Management console from search or Administrative tools from Control Panel. Next collapse Group Policy Management >> Forest:DomainName(vCloud.lab) >> Domains >> DomainName(vCloud.lab) >> Group Policy Objects. Right click GPO (Group Policy Objects), and create a new policy. It is always best practive to have new policy for new setting instead of doing all the settings in one policy and also for any new policy create it under Group Policy Objects and link it later once your configuration is done.
Give policy some name, mine is Local_Administrators (Always use some good naming convention which I can understand afterwords). And click ok.
Now right click new created Local_Administrators policy. Edit it. To configure it,
Now collapse Computer Configuration Node >> Policies >> Windows Settings >> Security Settings >> Restricted Groups. Right click and Open Group. This will open another pop up window.
Here browse and add the Group which you want to add to Local machine Group. I have already created a group Server_Administrators in AD
Once the Group name vcloud\Server_Administrators is reflected in Group box, click OK for next.
Once you click ok this window will be closed, this group policy is created and it will be shown in right pane of Restricted Groups, here you have two options,
 

Members of this group: Use this option when you want create local group on machines. (as above step instead of browsing you can type some name for Group, it will be created on client machines) This group is member of: We are going to use this option as we want to add this AD Group to local machines Administrators. Click add button type Administrators, (Do not browse).
As per below screenshot AD Group Server_Administrators will be member of local Administrators group. Click OK button.
If everything is good as per below screenshot you should see Group name and Member of as expected. And close this GPO by clicking cross button, without this Group policy changes are not saved. (Many times I forgot this step while testing :))

Next is linking Local_Administrators GPO to OU where your computer accounts are residing, Mine are residing under vCloud.lab >> Computers. Right click Computers OU, Click Link an Existing GPO.
Select Local_Administrators GPO from the list. And click OK. This was the final configuration step on the Group Policy server.
When you see Computer OU, it will show Local_Administrators GPO as linked (shortcut icon), and also under Linked Group Policy Objects tab. Server side configuration is done now. It’s time to check on member machines.


On member computer servers (Client001 part of Computers OU), we need to verify whether changes has been applied, start run and open compmgmt.msc.


It opens Computer Management, Collapse System Tools. Go to groups under Local Users and Groups. And double click or go to properties of Administrators account.

If you check it, you won’t find group added, because it will take at least 90 mins to apply changes, This is the point where we have create GPO, linked it to OU but computers are not aware of it.

Instead of waiting for next cycle we can get policies applied immediately, for the same run “gpupdate /force” or reboot the server, Next generate the report what changes has been applied from group policy by running command “gpresult /h report.html”. You must be running cmd run as administrator to pull computer node configuration. Open report by executing command “start report.html”, It will open the web page
In this web page you can verify computer account, Group policy which has been applied, and under Computer configuration node, Restricted Groups is applied successfully. It shows everything what is failed and what is successfully applied.
Finally check Administrators properties again and hopefully you can see AD Group is added to local Group. And your PC is compliant now.




Monday, September 7, 2015

Powercli Pull CDP and LLDP information in single nice table format - Part 2


Today I received newsletter email from psvmware.wordpress.com, He has written nice blog subject Get-VMHostPnicCDP for check CDP/LLDP information for ESXi hostsystem physical nic. He has really done good job,
After seeing his blog I remembered, Long back I had also written script to pull information CDP and LLDP from vCenter servers. I had  already posted script for only CDP - PowerCLI esxi host Physical nic info in nice table format 

Below script for pull both the information for CDP and LLDP, I tested it long back working. Copy script it test, save as extension .PS1, make sure your machine execution policy is no restricted. Change the IP to your vcenter or esxi server.

Other Useful Scripts:

Save complete virtual PortGroup information Settings - Powercli


 #####################################   
  ## http://kunaludapi.blogspot.com   
  ## Version: 1   
  ##   
  ## Tested this script on   
  ## 1) Powershell v3   
  ## 2) Powercli v5.5   
  ## 3) Vsphere 5.x   
  #####################################   
 Add-PSSnapin VMware.VimAutomation.core   
 Add-PSSnapin VMware.VimAutomation.Vds   
  $vCenterCred = Get-Credential -Message "vCenter server or esxi credentials"   
  $vcenterServer = "192.168.33.21"   
  Connect-viServer -server $vcenterServer -Credential $vCenterCred   
  $Collection = @()   
  $Esxihosts = Get-VMHost rginitesx003.rageprod.com ,rginitesxsrv15.rageprod.com #| Where-Object {$_.ConnectionState -eq "Connected"}   
  foreach ($Esxihost in $Esxihosts) {   
   $Esxcli = Get-EsxCli -VMHost $Esxihost   
   $Esxihostview = Get-VMHost $EsxiHost | Get-View   
   $NetworkSystem = $Esxihostview.Configmanager.Networksystem   
   $Networkview = Get-View $NetworkSystem   
   $DvSwitchInfo = Get-VDSwitch -VMHost $Esxihost   
   if ($DvSwitchInfo -ne $null) {   
      $DvSwitchHost = $DvSwitchInfo.ExtensionData.Config.Host   
      $DvSwitchHostView = Get-View $DvSwitchHost.config.host   
      $VMhostnic = $DvSwitchHostView.config.network.pnic   
      $DVNic = $DvSwitchHost.config.backing.PnicSpec.PnicDevice   
   }   
   $VMnics = $Esxihost | get-vmhostnetworkadapter -Physical  #$_.NetworkInfo.Pnic   
   Foreach ($VMnic in $VMnics){   
     $realInfo = $Networkview.QueryNetworkHint($VMnic)   
     $pNics = $esxcli.network.nic.list() | where-object {$vmnic.name -eq $_.name} | Select-Object Description, Link        
     $Description = $esxcli.network.nic.list()   
     if ($vmnic.Name -eq $DVNic) {   
       $vSwitch = $DVswitchInfo | where-object {$DVNic -match $vmnic.Name} | select-object -ExpandProperty Name   
     }   
     else {   
       $vSwitchname = $Esxihost | Get-VirtualSwitch | Where-object {$_.nic -eq $VMnic.DeviceName}   
       $vSwitch = $vSwitchname.name   
     }   
     if ($realInfo.lldpinfo -ne $null) {  
       $LLDPinfo = $realInfo.lldpinfo  
       $SwitchName = $realInfo.lldpinfo.Parameter | Where-Object {$_.Key -eq "System Name"} | Select-Object -ExpandProperty Value  
       $SwitchIP = $realInfo.lldpinfo.Parameter | Where-Object {$_.Key -eq "Management Address"} | Select-Object -ExpandProperty Value  
       $SwitchPortVlanID = $realInfo.lldpinfo.Parameter | Where-Object {$_.Key -eq "Vlan ID"} | Select-Object -ExpandProperty Value  
       $SwitchPortMTU = $realInfo.lldpinfo.Parameter | Where-Object {$_.Key -eq "MTU"} | Select-Object -ExpandProperty Value  
       $Table = New-Object PSObject   
       $Table | Add-Member -Name EsxName -Value $esxihost.Name -MemberType NoteProperty   
       $Table | Add-Member -Name VMNic -Value $VMnic -MemberType NoteProperty   
       $Table | Add-Member -Name vSwitch -Value $vSwitch -MemberType NoteProperty   
       $Table | Add-Member -Name Link -Value $pNics.Link -MemberType NoteProperty    
       $Table | Add-Member -Name PortNo -Value $LLDPinfo.PortId -MemberType NoteProperty   
       $Table | Add-Member -Name SwitchName -Value $SwitchName -MemberType NoteProperty   
       $Table | Add-Member -Name SwitchIP -Value $SwitchIP -MemberType NoteProperty  
       $Table | Add-Member -Name MacAddress -Value $vmnic.Mac -MemberType NoteProperty   
       $Table | Add-Member -Name SpeedMB -Value $vmnic.ExtensionData.LinkSpeed.SpeedMB -MemberType NoteProperty   
       $Table | Add-Member -Name Duplex -Value $vmnic.ExtensionData.LinkSpeed.Duplex -MemberType NoteProperty   
       $Table | Add-Member -Name Pnic-Vendor -Value $pNics.Description -MemberType NoteProperty   
       $Table | Add-Member -Name Pnic-drivers -Value $vmnic.ExtensionData.Driver -MemberType NoteProperty   
       $Table | Add-Member -Name PCI-Slot -Value $vmnic.ExtensionData.Pci -MemberType NoteProperty   
       $collection += $Table  
     }  
     else {  
       $CDPextended = $realInfo.connectedswitchport  
       $Table = New-Object PSObject   
       $Table | Add-Member -Name EsxName -Value $esxihost.Name -MemberType NoteProperty   
       $Table | Add-Member -Name VMNic -Value $VMnic -MemberType NoteProperty   
       $Table | Add-Member -Name vSwitch -Value $vSwitch -MemberType NoteProperty   
       $Table | Add-Member -Name Link -Value $pNics.Link -MemberType NoteProperty    
       $Table | Add-Member -Name PortNo -Value $CDPextended.PortId -MemberType NoteProperty   
       $Table | Add-Member -Name SwitchName -Value $CDPextended.devID -MemberType NoteProperty   
       $Table | Add-Member -Name SwitchIP -Value $CDPextended.Address -MemberType NoteProperty  
       $Table | Add-Member -Name MacAddress -Value $vmnic.Mac -MemberType NoteProperty   
       $Table | Add-Member -Name SpeedMB -Value $vmnic.ExtensionData.LinkSpeed.SpeedMB -MemberType NoteProperty   
       $Table | Add-Member -Name Duplex -Value $vmnic.ExtensionData.LinkSpeed.Duplex -MemberType NoteProperty   
       $Table | Add-Member -Name Pnic-Vendor -Value $pNics.Description -MemberType NoteProperty   
       $Table | Add-Member -Name Pnic-drivers -Value $vmnic.ExtensionData.Driver -MemberType NoteProperty   
       $Table | Add-Member -Name PCI-Slot -Value $vmnic.ExtensionData.Pci -MemberType NoteProperty  
       $collection += $Table   
     }  
   }   
  }   
  $Collection | Sort-Object esxname, vmnic | ft *   
  Disconnect-VIserver * -confirm:$false   

Sunday, September 6, 2015

Connect-VIserver Could not connect using the requested protocol.

Today I wanted to build some critical script in my Lab. when I opened Powercli and tried to connect my vCenter I was receiving below error.
 ##################################################
Connect-VIServer :  6/08/2015 3:31:27 AM        Connect-VIserver          Could not connect using the requested protocol.
At line:1 char:1
+ Connect-VIServer itvc001.age.com
+
        + CategoryInfo               : ObjectNotFound: (:) [Connect-VIserver], ViServerConnectionException
        + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_ProtocolError, VMware.VimAutomation.ViCore.Cmd
    lets.Commands.ConnectVIServer
##################################################
In case you get below error, you can use same solution to resolve this issue.
The remote server returned an error: (407) Proxy Authentication Required

After many try on vmware KB I stumbled upon below KB and found the solution. This issue occurs due to the proxy settings in the environment.
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2011395 
To resolve this, check the proxy settings using the PowerCLI and set the proxy to No Proxy.
To set the proxy setting to No Proxy:

 1.Run this command to find the current proxy settings:
    Get-PowerCLIConfiguration
    You see an output similar to:

    C:\PS>Get-PowerCLIConfiguration

   Proxy Policy Default            Server Mode
   -------------------------       ---------------
   UseSystemProxy                  Single


    Note: This output indicates that the PowerCLI is using the System Proxy.

 2.To change this setting, run this command:
    Set-PowerCLIConfiguration -ProxyPolicy NoProxy -Confirm
    You see an output similar to:

  C:\PS>Set-PowerCLIConfiguration -ProxyPolicy NoProxy -Confirm

    Perform operation?

  Performing operation 'Update vSphere PowerCLI configuration.'?
  [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y

  Proxy Policy Default       ServerMode
  ------------               ---------------
  NoProxy                    Single


Once above changes done I am able to login successfully.

Upgrade Firmware (iDRAC and LifeCycle Manager) on Dell PowerEdge R910 Rack server running VMware ESXi

Upgrade Firmware (BIOS) on Dell PowerEdge R910 Rack server running VMware ESXi
Upgrade Firmware (iDRAC and LifeCycle Manager) on Dell PowerEdge R910 Rack server running VMware ESXi 



Earlier article I used bootable bios CD to upgrade firmware, here I will be upgrading iDRAC and lifecycle manager, I have shown how to download them from support.dell.com in my earlier article (BIOS upgrade). Files are kept at location.
C:\Dell_PowerEdge_R910_Firmwares\R910_iDRAC_ 1.97_firmimg.d6
C:\Dell_PowerEdge_R910_Firmwares\R910_Lifecycle_Manager_BDF_1.5.0_BIN-25_A00.usc


Once your esxi server is rebooted after upgrading bios, Next go to iDRAC Settings>update (on iDRAC). In the File path select C:\Dell_PowerEdge_R910_Firmwares\R910_iDRAC_ 1.97_firmimg.d6, upload the file.
It will take time on your network connection speed to iDRAC to upload file, so have a patience and sit back :) .
Once the file upload process completed it will show current version and new version, Press next to
proceed if everything is good.
Press ok to confirm update on the poped up winodw, and it will be showing process in %, also it might take around 15 to 20 mins.
Once the process completed wait for next 10-15 Mins, As iDrac is getting restarted and you loose the connection to iDRAC for some time. Close browser and open Drac console in new browser. (It will take around 10-15 mins to reboot iDRAC and show the page on browser)
Here step is completed for iDRAC. Next is Lifecycle controller upgrade
Use the same procedure used to update iDRAC firmware, provide file path in Firmware update C:\Dell_PowerEdge_R910_Firmwares\R910_Lifecycle_Manager_BDF_1.5.0_BIN-25_A00.usc, and proceed with update, nothing much fancy.


Next verify the before and after version.


Upgrade Firmware (BIOS) on Dell PowerEdge R910 Rack server running VMware ESXi

Upgrade Firmware (BIOS) on Dell PowerEdge R910 Rack server running VMware ESXi
Upgrade Firmware (iDRAC and LifeCycle Manager) on Dell PowerEdge R910 Rack server running VMware ESXi

Firmware is permanent software programmed into a read-only memory, It is a combination of software and hardware. for example BIOS, it is written on the BIOS chip on the motherboard, if that fails Machine would not start. BIOS has all the instructions whats need to be done once Machine is powered on and how to boot OS.

Why firmware update is required?
Many times Manufacturers make improvements in there firmware programs, they remove bugs. One of the example of improvement is, Old firmware version may not compatible with New OS, but after upgrading Firmware you see improvement and supported new OS.

It is very easy to upgrade firmware on Windows Server, you can simply download firmware files from http://support.dell.com, and just run those programs (Dell provides there flash utility and firmware which can be easily run on windows or Linux, As they are in known exe or rpm format, Same is not supported on ESXi).  

This is my step by step guide on upgrading BIOS on Dell Poweredge R910 running OS VMWare Esxi. This is complete manual process. (You can create your own bootable CD for bios and boot from it and flash bios, I will be covering this article in another blog for creating your own Boot file), I have called Dell support and they created one Bootable CD for me and I have downloaded it over there FTP site.

Next I downloaded iDRAC and Lifesycle controller files from support website of dell.
All my flash files are on 
C:\Dell_PowerEdge_R910_Firmwares\R910_Bios_Linux_ Bootable_2.10.iso
C:\Dell_PowerEdge_R910_Firmwares\R910_iDRAC_ 1.97_firmimg.d6
C:\Dell_PowerEdge_R910_Firmwares\R910_Lifecycle_Manager_BDF_1.5.0_BIN-25_A00.usc

Next Open iDrac in website, and note down the current firmware version of the server, Its on the first web page once you login.

Launch console, on the middle top or under drop down menu, Virtual Media>Launch Virtual Media.
Add bootable BIOS cd image from location (C:\Dell_PowerEdge_R910_Firmwares\R910_Bios_Linux_Bootable_2.10.iso), it will map to r910 as a Virtual CD, and you can boot from it. (Reboot will be required after this step (Note: Before rebooting make sure you have Migrated all the VMs to another esxi host, put esxi server into Maintenance Mode for best practice))
Click check Mapped box it will mount ISO on the server in virtual CD/DVD.
(Note: Before rebooting make sure you have Migrated all the VMs to another esxi host, put esxi server into Maintenance Mode for best practice), You will need to reboot your server, while first post Press F10 or go to bios and select boot from Virtual CD. Once It is booted just sit back, it will automatically update BIOS and reboot. It is Linux CD and will be running shell .sh script to update firmware once boot.

Once Bios upgrdation Step is completed, restart server and boot into Esxi server. You can verify Dell bios version on next article iDRAC webpage where i have uploaded screenshot. Next article i will be covering up on iDRAC upgradation, Which i downloaded from the Dell website.

Saturday, September 5, 2015

Multiple ways to Install Software remotely on Windows - Method 8 Task scheduler

Multiple ways to Install software remotely 
Multiple ways to Install Software remotely on Windows - Method 1 Group Policy 
Multiple ways to Install Software remotely on Windows - Method 2 Third party softwares

Multiple ways to Install Software remotely on Windows - Method 3 Command line PSEXEC tool
Multiple ways to Install Software remotely on Windows - Method 4 WMI (Windows Management Instrumentation)
Multiple ways to Install Software remotely on Windows - Method 5 PowerShell Remoting
Multiple ways to Install Software remotely on Windows - Method 6 PowerShell DSC (Desired State Configuration)
Multiple ways to Install Software remotely on Windows - Method 7 Copy Portable applications
Multiple ways to Install Software remotely on Windows - Method 8 Task scheduler

This is my last article for installing software remotely If anyone find or know any other solution to install software remotely I would be happy to cover it here as method 9. I started using scheduled task lately to perform my activities remotely, and What I found about Task scheduler doesn't require any extra setup or tool, because it is already there in windows by default and even you can connect to workgroup pc easily with it. If you take example of group policy, your system should be in domain, for third party and psexec you will need to download and use them, for powershell PS remoting must be enabled to work on remote server.

You can use it in below scenarios.
  • You don't want to use any tool.
  • You don't want to setup anything extra.
  • You want to schedule installation.

Its very easy to connect to schedule task remotely, setup a schedule and you are done. Best thing about it is you can schedule it, In this article I will be showing Patch or Hotfix installation remotely. To install patches in unattended mode, we will need to find parameters, to find them open command prompt or run type the hotfix file name and extension and append /h for help as shown below. (Here i am installing PowerShell upgrade remotely)
  
Here we will need to use parameters /quiet and /norestart as shown in windows update standalone installer screenshot.
Next Open task scheduler right click Task Scheduler > Connect to Another Computer, type the name computer you want to connect.
As you can see Task scheduler has connected to Clinet001.vlcoud.lab instead of local, Select Task Scheduler Library right click and create Basic Task.
Give some name to task, and it will trigger once only for me.
Setup some trigger time according to your need. and select start a program.
Next step is critical, Browse the program kept on shared drive. And provide parameters for silent installation, and last Finish shows summary whatever you have scheduled.
Next is very important configuration right click installpowershell and got to properties. (Without this schedule may fail)
In the properties you must select Run whether user is logged on or not and Run with highest privileges, This is self explanatory. And supply the admin user name password to run the task with.
Once this is done you just have have to wait for your schedule time or right click schedule and run right away to execute program. (Once installation is done verify on remote server and delete the schedule.) My schedule status is Ready to run.
Once I click ok status will change to running (you will have to refresh the screen by clicking on the empty space), Once you verify software is installed on remote server you can delete the schedule.

Now this was the GUI version, How you can achieve the same with command line.
There is a inbuilt tool called schtask.exe below is the creation example. Green marked area you can change as per your need.
schtasks.exe /create /S client001 /RU vcloud\vKunal /RP Computer@1 /SC Once /TN InstallProgram /TR "\\ad001\Softwares\PowershellV3\Powershell v3 Windows6.1-KB2506143-x64.msu /quiet /norestart" /ST 13:30  
It will create one schedule task. Next you can run it through same command schtasks.exe.
schtasks.exe /run /S client001 /TN InstallProgram
Now verify your application has installed correctly you can check history tab of task to view any errors., Once you check application install delete it now.
schtasks.exe /delete /S client001 /TN InstallProgram /F
You can use above 3 command in one batch file and create a script for remote installation.

Beauty of Task scheduler is you can even schedule it through Group Policy if you don't want to go with command line or scripting.

if you want it to do through powershell way there are cmd let available for schedule task in windows server 2012 r2 and windows 8.1 and above. (In powershell v5).
Disable-ScheduledTask
Enable-ScheduledTask
Export-ScheduledTask
Get-ClusteredScheduledTask
Get-ScheduledTask
Get-ScheduledTaskInfo
New-ScheduledTask
New-ScheduledTaskAction
New-ScheduledTaskPrincipal
New-ScheduledTaskSettingsSet
New-ScheduledTaskTrigger
Register-ClusteredScheduledTask
Register-ScheduledTask
Set-ClusteredScheduledTask
Set-ScheduledTask
Start-ScheduledTask
Stop-ScheduledTask
Unregister-ClusteredScheduledTask
Unregister-ScheduledTask

Below are the parameter for schedule task create schtask.exe.
 SCHTASKS /Create [/S system [/U username [/P [password]]]]  
   [/RU username [/RP password]] /SC schedule [/MO modifier] [/D day]  
   [/M months] [/I idletime] /TN taskname /TR taskrun [/ST starttime]  
   [/RI interval] [ {/ET endtime | /DU duration} [/K] [/XML xmlfile] [/V1]]  
   [/SD startdate] [/ED enddate] [/IT | /NP] [/Z] [/F] [/HRESULT] [/?]  
 Description:  
   Enables an administrator to create scheduled tasks on a local or  
   remote system.  
 Parameter List:  
   /S  system    Specifies the remote system to connect to. If omitted  
             the system parameter defaults to the local system.  
   /U  username   Specifies the user context under which SchTasks.exe   
             should execute.  
   /P  [password]  Specifies the password for the given user context.  
             Prompts for input if omitted.  
   /RU username   Specifies the "run as" user account (user context)  
             under which the task runs. For the system account,  
             valid values are "", "NT AUTHORITY\SYSTEM"  
             or "SYSTEM".  
             For v2 tasks, "NT AUTHORITY\LOCALSERVICE" and   
             "NT AUTHORITY\NETWORKSERVICE" are also available as well   
             as the well known SIDs for all three.   
   /RP [password]  Specifies the password for the "run as" user.   
             To prompt for the password, the value must be either  
             "*" or none. This password is ignored for the   
             system account. Must be combined with either /RU or  
             /XML switch.  
   /SC  schedule   Specifies the schedule frequency.  
             Valid schedule types: MINUTE, HOURLY, DAILY, WEEKLY,   
             MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT.  
   /MO  modifier   Refines the schedule type to allow finer control over  
             schedule recurrence. Valid values are listed in the   
             "Modifiers" section below.  
   /D  days     Specifies the day of the week to run the task. Valid   
             values: MON, TUE, WED, THU, FRI, SAT, SUN and for  
             MONTHLY schedules 1 - 31 (days of the month).   
             Wildcard "*" specifies all days.  
   /M  months    Specifies month(s) of the year. Defaults to the first   
             day of the month. Valid values: JAN, FEB, MAR, APR,   
             MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC. Wildcard "*"   
             specifies all months.  
   /I  idletime   Specifies the amount of idle time to wait before   
             running a scheduled ONIDLE task.  
             Valid range: 1 - 999 minutes.  
   /TN  taskname   Specifies a name which uniquely  
             identifies this scheduled task.  
   /TR  taskrun   Specifies the path and file name of the program to be   
             run at the scheduled time.  
             Example: C:\windows\system32\calc.exe  
   /ST  starttime  Specifies the start time to run the task. The time   
             format is HH:mm (24 hour time) for example, 14:30 for   
             2:30 PM. Defaults to current time if /ST is not   
             specified. This option is required with /SC ONCE.  
   /RI  interval   Specifies the repetition interval in minutes. This is   
             not applicable for schedule types: MINUTE, HOURLY,  
             ONSTART, ONLOGON, ONIDLE, ONEVENT.  
             Valid range: 1 - 599940 minutes.  
             If either /ET or /DU is specified, then it defaults to   
             10 minutes.  
   /ET  endtime   Specifies the end time to run the task. The time format  
             is HH:mm (24 hour time) for example, 14:50 for 2:50 PM.  
             This is not applicable for schedule types: ONSTART,   
             ONLOGON, ONIDLE, ONEVENT.  
   /DU  duration   Specifies the duration to run the task. The time   
             format is HH:mm. This is not applicable with /ET and  
             for schedule types: ONSTART, ONLOGON, ONIDLE, ONEVENT.  
             For /V1 tasks, if /RI is specified, duration defaults   
             to 1 hour.  
   /K         Terminates the task at the endtime or duration time.   
             This is not applicable for schedule types: ONSTART,   
             ONLOGON, ONIDLE, ONEVENT. Either /ET or /DU must be  
             specified.  
   /SD  startdate  Specifies the first date on which the task runs. The   
             format is mm/dd/yyyy. Defaults to the current   
             date. This is not applicable for schedule types: ONCE,   
             ONSTART, ONLOGON, ONIDLE, ONEVENT.  
   /ED  enddate   Specifies the last date when the task should run. The   
             format is mm/dd/yyyy. This is not applicable for   
             schedule types: ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT.  
   /EC  ChannelName Specifies the event channel for OnEvent triggers.  
   /IT        Enables the task to run interactively only if the /RU   
             user is currently logged on at the time the job runs.  
             This task runs only if the user is logged in.  
   /NP        No password is stored. The task runs non-interactively  
             as the given user. Only local resources are available.  
   /Z         Marks the task for deletion after its final run.  
   /XML xmlfile   Creates a task from the task XML specified in a file.  
             Can be combined with /RU and /RP switches, or with /RP   
             alone, when task XML already contains the principal.  
   /V1        Creates a task visible to pre-Vista platforms.  
             Not compatible with /XML.  
   /F         Forcefully creates the task and suppresses warnings if   
             the specified task already exists.  
   /RL  level    Sets the Run Level for the job. Valid values are   
             LIMITED and HIGHEST. The default is LIMITED.  
   /DELAY delaytime  Specifies the wait time to delay the running of the   
             task after the trigger is fired. The time format is  
             mmmm:ss. This option is only valid for schedule types  
             ONSTART, ONLOGON, ONEVENT.  
   /HRESULT      For better diagnosability, the process exit code  
             will be in the HRESULT format.  
   /?         Displays this help message.  
 Modifiers: Valid values for the /MO switch per schedule type:  
   MINUTE: 1 - 1439 minutes.  
   HOURLY: 1 - 23 hours.  
   DAILY:  1 - 365 days.  
   WEEKLY: weeks 1 - 52.  
   ONCE:  No modifiers.  
   ONSTART: No modifiers.  
   ONLOGON: No modifiers.  
   ONIDLE: No modifiers.  
   MONTHLY: 1 - 12, or   
        FIRST, SECOND, THIRD, FOURTH, LAST, LASTDAY.  
   ONEVENT: XPath event query string.  
 Examples:  
   ==> Creates a scheduled task "doc" on the remote machine "ABC"  
     which runs notepad.exe every hour under user "runasuser".   
     SCHTASKS /Create /S ABC /U user /P password /RU runasuser  
          /RP runaspassword /SC HOURLY /TN doc /TR notepad   
   ==> Creates a scheduled task "accountant" on the remote machine   
     "ABC" to run calc.exe every five minutes from the specified  
     start time to end time between the start date and end date.  
     SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE  
          /MO 5 /TN accountant /TR calc.exe /ST 12:00 /ET 14:00  
          /SD 06/06/2006 /ED 06/06/2006 /RU runasuser /RP userpassword  
   ==> Creates a scheduled task "gametime" to run freecell on the   
     first Sunday of every month.  
     SCHTASKS /Create /SC MONTHLY /MO first /D SUN /TN gametime   
          /TR c:\windows\system32\freecell  
   ==> Creates a scheduled task "report" on remote machine "ABC"  
     to run notepad.exe every week.  
     SCHTASKS /Create /S ABC /U user /P password /RU runasuser  
          /RP runaspassword /SC WEEKLY /TN report /TR notepad.exe  
   ==> Creates a scheduled task "logtracker" on remote machine "ABC"  
     to run notepad.exe every five minutes starting from the  
     specified start time with no end time. The /RP password will be  
     prompted for.  
     SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE  
          /MO 5 /TN logtracker   
          /TR c:\windows\system32\notepad.exe /ST 18:30  
          /RU runasuser /RP  
   ==> Creates a scheduled task "gaming" to run freecell.exe starting  
     at 12:00 and automatically terminating at 14:00 hours every day  
     SCHTASKS /Create /SC DAILY /TN gaming /TR c:\freecell /ST 12:00  
          /ET 14:00 /K  
   ==> Creates a scheduled task "EventLog" to run wevtvwr.msc starting  
     whenever event 101 is published in the System channel  
     SCHTASKS /Create /TN EventLog /TR wevtvwr.msc /SC ONEVENT  
          /EC System /MO *[System/EventID=101]   
   ==> Spaces in file paths can be used by using two sets of quotes, one  
     set for CMD.EXE and one for SchTasks.exe. The outer quotes for CMD  
     need to be double quotes; the inner quotes can be single quotes or  
     escaped double quotes:  
     SCHTASKS /Create   
       /tr "'c:\program files\internet explorer\iexplorer.exe'   
       \"c:\log data\today.xml\"" ...   

Thursday, September 3, 2015

Multiple ways to Install Software remotely on Windows - Method 7 Copy Portable applications

Multiple ways to Install software remotely
Multiple ways to Install Software remotely on Windows - Method 1 Group Policy
Multiple ways to Install Software remotely on Windows - Method 2 Third party softwares

Multiple ways to Install Software remotely on Windows - Method 3 Command line PSEXEC tool
Multiple ways to Install Software remotely on Windows - Method 4 WMI (Windows Management Instrumentation)
Multiple ways to Install Software remotely on Windows - Method 5 PowerShell Remoting
Multiple ways to Install Software remotely on Windows - Method 6 PowerShell DSC (Desired State Configuration)
Multiple ways to Install Software remotely on Windows - Method 7 Copy Portable applications
Multiple ways to Install Software remotely on Windows - Method 8 Task scheduler

All the methods I shown earlier were based on installation setup means I was installing them remotely, What if you don't have setup file (exe or msi) to install, you have only portable software, something like just putty.exe, or some other standalone tool. You can copy single or couple files using group policy, check my blog Copy files on computers using group policy. 

(Now a days I am seeing portable software is good choice when you don't have admin rights on your server and wants to install or run utilities)

for this reason I am including this as method (To work this method correctly C$ hidden share must be enabled on the remote server). I have program called treesize, it show the drive and folder size utilization to track space. My portable software is kept on shared drive and I created shortcut file for its exe executable software. (see the target its pointing towards UNC path and exe)
Now you can manually Access the UNC path of  C$\Users\Public\Desktop can copy this portable file, it will be automatically reflected on each users desktop on that machine.

or if you want to script simple run command
xcopy c:\Softwares\TreeSize\TreeSizeFreePortable.lnk \\client001\c$\Users\Public\Desktop
when you see check on the remote machine you will able able to access those programs. You can also copy same shortcut under C$\Programdata\Microsft\Windows\Start Menu, you will see the same shortcut in everyone start menu.

If in case C$ is not shared or disabled This same process you done by Copying files on computers using group policy.

Next is very great method call schedule task. that would be last post for installation of software remotely in these series.

Wednesday, September 2, 2015

Multiple ways to Install Software remotely on Windows - Method 6 PowerShell DSC (Desired State Configuration)

Multiple ways to Install software remotely
Multiple ways to Install Software remotely on Windows - Method 1 Group Policy
Multiple ways to Install Software remotely on Windows - Method 2 Third party softwares

Multiple ways to Install Software remotely on Windows - Method 3 Command line PSEXEC tool
Multiple ways to Install Software remotely on Windows - Method 4 WMI (Windows Management Instrumentation)
Multiple ways to Install Software remotely on Windows - Method 5 PowerShell Remoting
Multiple ways to Install Software remotely on Windows - Method 6 PowerShell DSC (Desired State Configuration)
Multiple ways to Install Software remotely on Windows - Method 7 Copy Portable applications
Multiple ways to Install Software remotely on Windows - Method 8 Task scheduler 

DSC (Desired state configuration) is a very cool method of performing task remotely. I am seeing over the period Microsoft is evolving it script technology to make life more hassle free.

What is DSC (Desired State configuration)?
In my words DSC uses WS-Management protocol (WinRM) it made to push configuration on remote server or pull information from DSC server.  (To see how i enabled WinRM service please check my blog Method 5 PowerShell Remoting) Once you run DSC command you are telling remote computer that its configuration must be according what I have defined. In simple terms It is same as Group Policy.
Prerequisite to use DSC is your computers should have at least powershell Version 4. They are by default there on windows 2012 and windows 8 and above. Next, Make sure your applications are kept on Shared drive, This is another requirement. Here script ps1 execution is required so we need to unrestrict them inside PowerShell.

Open Powershell with run as administrator and command, This need to be run on the server from where you will be pushing Softwares to remote servers.
Set-ExecutionPolicy unrestricted -force

Before going forward, every software has some productID and it is necessary for deployment, without productid you will get error but softwares installation will not fail, so for error free, here I am showing trick to find product id for any software on windows. Install software on any windows machine (as this is a Java demo, I have installed it my one of the server), Open powershell  and fire up command 
Get-WmiObject -Query "Select Name, Caption, IdentifyingNumber from Win32_product Where Name Like 'Java%'"
It will find all the products names starting with Java and the very next is Identifyingnumber is a product ID.
Next all scripts are stored on c:\temp file below script (From this server i will be pushing software remotly) I have saved it as javainstall.ps1.


Configuration JavaInstallation {
    param ($ComputerName)
    Node $ComputerName {
        Package InstallJAVA {
            Ensure = "Present"
            Name = "Install JAVA"
            Path = "\\AD001\Softwares\JAVAInstallation\jre-8u60-windows-i586.exe"
            Arguments = "/s"

            ProductID = "26A24AE4-039D-4CA4-87B4-2F83218060F0"
        }
    }
}
JavaInstallation -ComputerName AD002


As you can see above I am in c:\temp directory JAVAinstall.ps1 and only the content marked in orange you will need to change accordingly, (Setup path and Argument). The computer name must be netbios name not the IP.

Next open powershell, change directory to c:\temp (cd c:\temp). and execute ps1 file .\JAVAinstall.ps1.
Once you execute it will create folder in same directory and mof file under it for the remote servesr (MOF file will contain all the configuration required to configure remote server) If you have assigned multiple server names in the script it will create each mof file for each server with its respective name.
Now everything is ready, we just need to push file with command Start-DSCConfiguration. 
Start-DSCConfiguration c:\temp\JavaInstallation -Wait
it is pushing all the mof files from c:\temp\javainstallation location now. 
To view results simply check installed programs on remote server.
Next method is setup copy method, cool method for installing portable setup files. go ahead check yourself Method 7 Copy Portable applications Install software remotely.

Saturday, August 29, 2015

Multiple ways to Install Software remotely on Windows - Method 5 Powershell Remoting

Multiple ways to Install software remotely
Multiple ways to Install Software remotely on Windows - Method 1 Group Policy
Multiple ways to Install Software remotely on Windows - Method 2 Third party softwares

Multiple ways to Install Software remotely on Windows - Method 3 Command line PSEXEC tool
Multiple ways to Install Software remotely on Windows - Method 4 WMI (Windows Management Instrumentation)
Multiple ways to Install Software remotely on Windows - Method 5 PowerShell Remoting
Multiple ways to Install Software remotely on Windows - Method 6 PowerShell DSC (Desired State Configuration)
Multiple ways to Install Software remotely on Windows - Method 7 Copy Portable applications 
Multiple ways to Install Software remotely on Windows - Method 8 Task scheduler 

In this article I will be covering remote installation using powershell. Powershell is windows scripting tool and may replace cmd (Command prompt) gradually over the time. Powershell has remoting feature as same as ssh in linux. Powershell uses WS-Manangement protocol to connect remotely, and it need to be enabled on remote server (as same as remote desktop).

Requirement is both the server and client should have powershell installed. below steps done to enable psremoting.

Start PowerShell as administrator and fire below command.

Enable-PSRemoting 

Basically it does below main things  
Start WinRM service (Windows Remote Management (WS-Management)), set to auto automatic start. Add any hosts * in the listeners (clients) list (any computers in the same domain can connect over WINRM protocol), and the last thing is to enable firewall exception for WS-management traffic. 

Type couple of Y to agree all the required changes. This need to be setup on remote server. And you are ready to connect.

In this section I will be using SCCM client to install remotely, as usual it is located on shared drive, From any other server open powershell, Go with the below command. Line in the bold is invoke-command (to execute command remotely) and you will need to replace hostname according to your need (provide netbios name only, To work IP address correctly you will need to add ips to trusted host list.),  In the curly brackets I have executed SCCM client kept on shared drive, ccmsetup.exe with its parameters pointing toward site code and other info.

Invoke-Command -ComputerName Client001 -Command {\\ad001\Softwares\SCCMClient\CCMSetup.exe /mp:SMSMP01 /logon SMSSITECODE=S01 FSP=SMSFSP01}

Here you are done and you can check on the remote server for Installed application. 
There are more methods I will be addressing in my next articles.

Next is Powershell DSC Desire state configuration to install software remotely in line.
Method 6 PowerShell DSC (Desired State Configuration) install software remotely.