Loading

Endregion

Skip Feed
  1. DUJ Status powershell

     

    Hello all,

     

    I'm sure we all have seen the new DUJ status indicator in the SLM Web UI

    dujstatus 

    There is also already an idea in the ideas board to restrict visibility for this:

    https://ideas.snowsoftware.com/ideas/IDEAS-I-1519

     

    I was wondering where this information comes from and the answer is so easy.

    There is a new url in the API for this: http(s)://snowserver:port/api/duj

    This results in

    DUJStatus1 

    So, I thought I'd like to monitor this using a powershell script and ended up with this (please note that this is not the "best" powershell scripting, my focus was to demonstrate how it works):

    ------------------------------------------------------------------------------------------------------------------------------

    function SLMGetDUJStatus {

       param()

     

       #region Settings TEST, optional use this as parameters in the function

           $SLMAccountName = "YourSLMAPIAccountName"

           $SLMAccountPW = "YourSLMAPIPassword"

           $SecurePassword = ConvertTo-SecureString $SLMAccountPW -asPlainText -Force

           $SLMServerName = "http://YourSLMServer:port"

       #endregion TEST

     

    Write-Verbose "SLMGetDUJStatus: Start"

     

       #region Credential and base uri to Snow License Manager

           $credential = New-Object Management.Automation.PSCredential ($SLMAccountName,$SecurePassword)

           $apiUri = "$SLMServerName/api/duj"

       #endregion TEST

     

       try {

           # Get status from Snow License Manager

           $SLMDUJ = Invoke-RestMethod -Uri ("$apiUri" + '?$format=json') -Credential $credential

     

           #create object to return values

           $return = New-Object PsObject         # create object for result

           # Add properties to the Object for DUJ Status

           $null = $return | Add-Member -Type NoteProperty -Name "DUJState" -Value "$($SLMDUJ.Body.state)" -Force

           $null = $return | Add-Member -Type NoteProperty -Name "DUJLastExec" -Value "$($SLMDUJ.Body.LastStartTime)" -Force

           $null = $return | Add-Member -Type NoteProperty -Name "DUJLastDuration" -Value "$($SLMDUJ.Body.LastExecutionTime)" -Force

           $null = $return | Add-Member -Type NoteProperty -Name "DUJIsRunning" -Value "$($SLMDUJ.Body.IsRunning)" -Force                       

     

           # Send object to the pipeline, so that it is returned

           $return

     

       } #try

       catch {

           Write-Verbose -verbose "Unable to get information. Exception: $($_.Exception.Message)"

       } #catch

    } # end function

     

    $status = SLMGetDUJStatus

    ------------------------------------------------------------------------------------------------------------------------------

     

    The result written to $status will be the object as defined:

    DUJStatus2 

    Hope this helps a little to understand SLM API and possibilities 😊

     

    Kine regards,

    Axel

    Expand Post

  2. How to use Array content in a PSObject as drop down values
    Hi @ll, Probably the solution is again very simple, nevertheless the problem presents me with a challenge. Based of some code from ‌ and the PSObject part from the AP PSWS"Get compliance info" , I use AP to collect information from SLM, no big deal! function GetSLMApplicationDetails {     param(       $applicationid   )     #region Settings           $SLMAccountName = Get-APSetting "SLMApiAccountName"           $SLMServerName  = Get-APSetting "SLMUri"           $SLMCustomerId  = Get-APSetting "SLMCustomerId"           $APPortalBaseAddress  = Get-APSetting "PortalBaseAddress"           $apiUserAccount = Get-ServiceAccount -Name $SLMAccountName       #endregion         #region Credential and base uri to Snow License Manager           $securePassword = ConvertTo-SecureString $($apiUserAccount.Password) -AsPlainText -Force           $credential = New-Object Management.Automation.PSCredential ($($apiUserAccount.AccountName), $securePassword)           $apiUri = "$SLMServerName/api/Customers/$SLMCustomerId/applications"       #endregion         $invokeUrl = "$apiUri/$applicationId/?" + '$format=json'         #region Get compliance details from Snow License Manager       $application = Invoke-RestMethod -Uri $invokeUrl -Credential $credential       $ApplicationName                                          = $application.body.Name                                           $ApplicationMetric                                        = $application.body.Metric         switch ($ApplicationMetric) {      "Installations" {$ApplicationMetric = "Installations"; break}      "TotalUsers" {$ApplicationMetric = "Users"; break}      "TotalCores" {$ApplicationMetric = "Number of processor cores"; break}      "TotalProcessors" {$ApplicationMetric = "Number of processors"; break}      default {$ApplicationMetric = "Installations"; break}      }   [...]                                             #License specific information   $LicenseAssignment = "Organisation","User","Site","Computer/datacenter"         # return object to pipeline       New-Object -TypeName psobject -Property @{           "ApplicationName"           = $ApplicationName           "ApplicationMetric"         = $ApplicationMetric           "LicenseAssignment" = $LicenseAssignment       }   } Running the code in PS the output looks good to me Adding the PSWS to my parameters (e.g.  "ApplicationName" and "LicenseAssignment") ApplicationName delivers the right content, but LicenseAgreement only shows me a "System.Object[]" I also tried it with the -join parameter in the psobject, but this didn't worked not as expected. Formated the content into one line instead of individual lines for the drop down "LicenseAssignment" = $LicenseAssignment -join "`r`n" The goal is to use a single PS WS that allows me to provide different information and not have to build an extra service for each field. Has any of you experienced how to correctly output arrays in a PSObject in AP? Thanks and Best, Dennis
    Expand Post

    1 of 5

  3. Computer Name from SLM
     I'm trying to figure out why the Powershell below seems to cause the memory consumption on the Server to go dramatically. I implemented the code on one Service and the memory with go up 10% but eventually go back down. If I implement it on all the Services it causes huge Memory issues. Any help is appreciated. function SLM_Computers   {   param($slmuser,$DeploymentType,$New_Hire,$BusinessArea, $AltUserID)     $apiAccountName = Get-APSetting "SLMApiAccountName"   $SLMServerName = Get-APSetting "SLMServerName"   $SLMCustomerId = Get-APSetting "CustomerId"       $apiUserAccount = Get-ServiceAccount -Name "$apiAccountName" -Scope 1   $securePassword = ConvertTo-SecureString $($apiUserAccount.Password) -AsPlainText -Force   $credential = New-Object Management.Automation.PSCredential ($($apiUserAccount.AccountName), $securePassword)   $version = 8         $cl = @()   #Verify Computer is in SCCM before placing in list   Function Search_Computer_SCCM   {   param ($Resource)     $SCCMServiceAccountName = Get-APSetting "SCCMServiceAccountName"   $SLMServerName = Get-APSetting "SCCMServer"   $SCCMUserName = Get-APSetting "SCCMUserName"   $SCCMServer = Get-APSetting "SCCMServer"   $SCCMSiteCode = Get-APSetting "SCCMSiteCode" $SCCMServiceAccount = Get-ServiceAccount -Name "$SCCMServiceAccountName" -Scope 0   $SCCMServiceAccountPassword = $SCCMServiceAccount.Password | ConvertTo-SecureString -AsPlainText -Force   $SCCMCredentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $SCCMUserName, $SCCMServiceAccountPassword   $extragwmiParameters = [ordered]@{   "Namespace" = "Root\SMS\Site_$SCCMSiteCode"   "ComputerName" = $SCCMServer   "Credential" = $Credentials   "ErrorAction" = 'Stop'   }   #endregion #region Validate Old SCCM resource     #Firsts checks if the resource is a device (computer)   if ($Resource.Contains('\'))   {   $OldDomainPart = $Resource.Split('\')[0]   $OldComputerNamePart = $Resource.Split('\')[1]   $OldResObj = @(Get-WmiObject -Class SMS_R_SYSTEM -Filter "Name = '$OldComputerNamePart' AND ResourceDomainORWorkgroup = '$OldDomainPart' AND Client = '1'" @extragwmiParameters)   }   else { $OldResObj = @(Get-WmiObject -Class SMS_R_SYSTEM -Filter "Name like '%$Resource%' AND Client = '1'" @extragwmiParameters) }     # if ($OldResObj.Count -gt 1) { throw "More than one device/computer with name $Resource found (with Client = 1)" } return $OldResObj.Name }   Function Search_Comp_SLM {   param($slmuser, $SnowAPICred)   $cl =@() $userapi =" http:// " + $SLMServerName + "/api/customers/1/users/?%24filter=endswith%28Username%2C%27" + $slmuser + "%27%29&`$top=100&`$format=json" $body = Invoke-RestMethod -Uri $userapi -Method Get -Credential $credential -disablekeepalive $SnowUserID = $body.Body.body.ID foreach ($s in $SnowUserID){   $compapi = " http:// "+ $SLMServerName + "/api/customers/1/users/" + $s + "/computers/?`$top=1000&`$format=json" $comptemp = Invoke-RestMethod -Uri $compapi -Method Get -Credential $credential -disablekeepalive $comps += $comptemp.body   }       #Evaluate parameter conditions   if ($DeploymentType -eq 'SCCM' -or $DeploymentType -eq 'Manual' -and $BusinessArea -eq "Commercial") {     $justcomps = $comps| ? {($_.Body.OperatingSystem -like "*Windows*") -and ($_.Body.OperatingSystem -notlike "*server*") -and ($_.Body.Organization -notlike "*T2017*") -and ($_.Body.Organization -notlike "*FED*") -and ($_.Body.Name -NOTlike "XD7-M*") }   ForEach($comp in $justcomps) {     #check if computer is in SCCM   $checkSCCM = Search_Computer_SCCM -Resource $comp.Body.Name   if ($checkSCCM) {   $cl += $comp.Body.Name     }   $checkSCCM = $   }   } elseif ($DeploymentType -eq 'SCCM' -or $DeploymentType -eq 'Manual' -and $BusinessArea -eq "T2017"){     $justcomps = $comps| ? {($_.Body.OperatingSystem -like "*Windows*") -and ($_.Body.OperatingSystem -notlike "*server*") -and ($_.Body.Organization -like "*T2017*") -and ($_.Body.Name -NOTlike "FEDVDAP*") }   $cl += $justcomps.Body.Name   }     elseif ($DeploymentType -eq 'SCCM' -or $DeploymentType -eq 'Manual' -and $BusinessArea -eq "T3"){     $justcomps = $comps| ? {($_.Body.OperatingSystem -like "*Windows*") -and ($_.Body.OperatingSystem -notlike "*server*") -and ($_.Body.Organization -like "*Fed*") }   $cl += $justcomps.Body.Name   }     elseif ($DeploymentType -eq 'MAC' -and $BusinessArea -eq "Commercial") {     $justcomps = $comps| ? {$_.Body.Manufacturer -like "*Apple*"}   $cl += $justcomps.Body.Name   } elseif ($DeploymentType -eq 'SCCM' -or $DeploymentType -eq 'Manual' -and $BusinessArea -eq "Fidelis") {     $justcomps = $comps| ? {($_.Body.OperatingSystem -like "*Windows*") -and ($_.Body.OperatingSystem -notlike "*server*") -and ($_.Body.Organization -notlike "*T2017*") -and ($_.Body.Organization -notlike "*FED*") -and ($_.Body.Name -NOTlike "XD7-M*") }   $cl += $justcomps.Body.Name }   return $cl }   $complist =@()     if (($New_Hire -eq 'Yes') -and ($DeploymentType -ne 'AD')){   $cl = 'Unknown'   }     if ($DeploymentType -eq 'AD'){   $cl = 'Citrix'   }     Else{   $complist += Search_Comp_SLM -slmuser $slmuser   if ($AltUserID){   $complist += Search_Comp_SLM -slmuser $Altuserid   }       } $complist | Sort-Object | Get-Unique   }
    Expand Post

    • Hi, I haven't been able to run your script myself, but perhaps I can help anyway. What happens if you run the script manually in PowerShell? Does the memory consumption look the same? Do you get a large amounts of objects from  Search_Comp_SLM ? What if you run the script without ever calling the SCCM function? Would that make it use less memory? I noticed that the function Search_Computer_SCCM refers to a variable called $Credentials which is never defined. The function Search_Comp_SLM refers to a variable called $credential which is not defined, but it has a parameter called $SnowAPICred which should probably be used instead. Perhaps a part of the script was not pasted in the post? In the end of the script I would suggest that you first filter the result before sorting it. Instead of: $complist | Sort-Object | Get-Unique‍ Do this: $complist | Get-Unique | Sort-Object‍ However, this should not affect performance much unless you are dealing with very large amounts of objects. Regards John
      Expand Post

  4. Software reassignment between workstations
    We are facing the following situation:   We would like to get all the software that is installed on a particular computer 1 (Software Portal)   and reinstall them on another computer 2.   Thus, all software on computer 1 would be installed on computer 2 and removed from computer 1.   We use SCCM to have computers included in installation and uninstallation collections   for each service (Software).

    1 of 13
    • Complete the first step successfully.  From the implementation of the script to its execution inside the Snow portal. I would like to thank the support provided by colleagues.  In addition, the following question arose:  How to pass to the portal a list of software that the computer has installed. select A.NAME AS Software from tblApplication AS A left join tabCID_cf_a_1 AS B on a.ApplicationID = b.ElementID LEFT JOIN tblComputerApplications AS C ON C.ApplicationID = A.ApplicationID LEFT JOIN tblComputer AS D ON D.ComputerID = C.ComputerID left join tblApplicationStoreData as E on e.ApplicationID = a.ApplicationID LEFT JOIN [SnowAutomationPlatformDomain].[DBO].[services] as portal on portal.name = a.name where OperatingSystem in ('Microsoft Windows 7 Enterprise','Microsoft Windows 10 Enterprise') and [Software Específco] = 1 and IsInstalled = 1 and HostName ='"+$ResSComp.NetbiosName+"'" I created a PS Web Service that receives the name of the computer and performs this query, but I do not know how to use it in the portal. The idea is to show in the portal a list of software that will be installed on the next computer. Thanks again to all.
      Expand Post

End of Feed
4 Chatter Feed Items
ALL CONVERSATIONS
UNSOLVED
ARTICLES
4 Posts
Loading
Endregion | Flexera