4 Replies Latest reply on Dec 16, 2016 1:31 AM by TomWhi

    PowerShell cmdlets Installation

    TomWhi Rookie

      Hi,

       

      I am new to the AppSense products so forgive me if I use any wrong terms.

       

      I have an installation of EM 8.6, AM 8.9 and MC 8.7 in our environment. I would like to be able to PowerShell query stuff out (anything about computers, their deployment group memberships etc.) and move computers between deployment groups.


      The problem I have is that I cannot find the PS cmdlet's installed on any of the servers, when I run the command Get-Module -Name AppSense* | Format-List it doesn't output anything - making me wonder if they are not installed.

       

      Please can anyone help me understand if they are installed by default; and if so where they are located or what command I can use to import them.

       

      TomWhi

        • 1. Re: PowerShell cmdlets Installation
          Roger1 Apprentice

          Check out this blog from Matt Walsh for some Management Center stuff - It might help answer your questions.  The module import requires that the Management Center Console be installed. I actually run the PowerShell commands from my PC rather than the server.  On a side note, I found I needed to have PowerShell 3.0 installed on the server to use the server specific modules included with AppSense (for example: to setup a failover partner for AMC).  The  API guides have a lot of information but are pretty cryptic for the less experienced (me).  However, Matt's blog is very easy to follow. 

           

          Blog post:

          AppSense Management Server Web Services API Overview | AppSense Blog

           

          A forum post I participated in that helped me find out how to move items: 

          AppSense Management Server API

          1 of 1 people found this helpful
          • 2. Re: PowerShell cmdlets Installation
            TomWhi Rookie

            Thanks for the fast response roger! Both of those links are really helpful and the tip about PSv3.

             

            I'll have to have a test run at Matt's blog to see if I can do a similar thing but it seems logical if not a little cumbersome after doing so much powershell stuff in the past. Hopefully they make some more cmdlets for day-to-day tasks to avoid having to call the API via web services

             

            Cheers

            Tom

            • 3. Re: PowerShell cmdlets Installation
              Roger1 Apprentice

              Thanks Tom.  Here's my script for moving computers listed in a computers.txt file if you're interested - This is stuff I grabbed from Matt's blog and through trial and error.  Please make sure to test it first as I am no PowerShell guru. 

               

               

               

              #Assigns all endpoints in the computers.txt to group $dgDestination

              function AssignMachines

              {

                

                     $function = "AssignMachines"

               

               

                      Write-Host -ForegroundColor Magenta "#########################"

                      Write-Host -ForegroundColor Magenta "##  Assign Machine to  ##"

                      Write-Host -ForegroundColor Magenta "##   Deployment Group  ##"

                      Write-Host -ForegroundColor Magenta "#########################"

               

               

                      $arrDepGroupKey = $GroupsWebService.GetDeploymentGroupsLight().Groups | select GroupKey

                      $arrDepName = $GroupsWebService.GetDeploymentGroupsLight().Groups | select Name

                      $arrDepName.Name

               

               

                  foreach ($epTarget in $epTargets) {

                      #####Change to Target Deployment Group#####

                      $dgDestination = "DeploymentGroup"

                               

                      $dgDestinationKey = $GroupsWebService.GetDeploymentGroupsLight().Groups | where-object {$_.Name -eq $dgDestination} | select GroupKey

                      #Computer Name

                      #$epTarget = $computer

                 

                      $epTargetKey =  $MachinesWebService.FindMachines('%').Machines | where-object {$_.NetBiosName -eq $epTarget} | select MachineKey

                      $dgSource = $MachinesWebService.FindMachines('%').Machines | where-object {$_.NetBiosName -eq $epTarget} | select GroupName

                      $dgSourceKey = $MachinesWebService.FindMachines('%').Machines | where-object {$_.NetBiosName -eq $epTarget} | select GroupKey

                      Write-Host -ForegroundColor Yellow "Machine is in the " $dgSource.GroupName "Group"

                      Write-Host -ForegroundColor Yellow "Moving $epTarget to $dgDestination"

                 

                      $MachinesWebService.Move($dgSourceKey.GroupKey, $dgDestinationKey.GroupKey, $epTargetKey.MachineKey)

                      Write-Host -ForegroundColor Yellow "Operation Complete, Machine is now part of ..."

                      $MachinesWebService.FindMachines('%').Machines | where-object {$_.NetBiosName -eq $epTarget} | select -property @{N='Deployment Group';E={$_.GroupName}}

                  }

              }

               

               

              ##----AppSense API module load and variable assignment----#

                  Add-Type -Path "${Env:ProgramFiles}\AppSense\Management Center\Console\ManagementConsole.WebServices.dll"

                  #####Change to correct Managment Server#####

                  $url = "http://SERVER/ManagementServer"

                  $credentials = [System.Net.CredentialCache]::DefaultCredentials

                  $credential = $credentials.GetCredential($url, "Basic")

                  [ManagementConsole.WebServices]::Connect($url, $credential)

                  $DiscoveredMachinesWebService = [ManagementConsole.WebServices]:: DiscoveredMachines

                  $MachinesWebService = [ManagementConsole.WebServices]:: Machines

                  $withSummary = $true

                  $MachinesDataSet = $MachinesWebService.GetMachines($withSummary)

                  $Machines = $MachinesDataSet.Machines

                  $AlertsWebService = [ManagementConsole.WebServices]::Alerts

                  $ConditionsWebService = [ManagementConsole.WebServices]::Conditions

                  $ConnectedURL = [ManagementConsole.WebServices]::ConnectedUrl

                  $DatabaseWebService = [ManagementConsole.WebServices]::Database

                  $DeploymentWebService = [ManagementConsole.WebServices]::Deployment

                  $EventsWebService = [ManagementConsole.WebServices]::Events

                  $GroupsWebService = [ManagementConsole.WebServices]::Groups

                  $LicensesWebService = [ManagementConsole.WebServices]::Licenses

                  $PackagesWebService = [ManagementConsole.WebServices]::Packages

                  $ProductsWebService = [ManagementConsole.WebServices]::Products

                  $ReportsWebService = [ManagementConsole.WebServices]::Reports

                  $SecurityWebService = [ManagementConsole.WebServices]::Security

                  $ServersWebService = [ManagementConsole.WebServices]::Servers

              ##----End module load----

              ####Change folder where computers.txt file lives####

              $epTargets = cat C:\TEMP\computers.txt

              AssignMachines

              • 4. Re: PowerShell cmdlets Installation
                TomWhi Rookie

                Fabulous, thank you. I'll be sure to read through it thoroughly before I even think of executing it anywhere