CPU script data collection - need help optimizing.

Hello

There is a follow-up on this topic:

http://communities.VMware.com/message/2192431

The script requires 3 Powershell and PowerCLI v5.1 Release 2.

Also the advice from here has been used:

http://vnugglets.com/2011/11/speed-up-first-PowerCLI-5-cmdlet.html

, The script connects to the x number of guests at the same time, gathers Intel cpu for the hosts and virtual machines and records them in csv files. This, it is the amount of time $counter, the Start-Sleep-s 10 is the less frequent verification.

Is there something I could remove or replace to make it less heavy resources? Please offer suggestions.
I know that $metrics is currently
useless

$Hosts = @(
"xx.xx.xx.1",
"xx.xx.xx.2",
"xx.xx.xx.3")
$metrics = "cpu.usage.average"
$counter = 5
 
foreach ($Server in $Hosts){
     Start-Job -ScriptBlock { 
          param ($Server, $metrics, $counter)
          Add-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue
          Connect-VIServer -Server $Server -user xxx -password "xxx" | Out-Null
          $vms = Get-Vm -Server $Server | where {$_.PowerState -eq "PoweredOn"}
 
          for ($i=0; $i -lt $counter; $i++){
               $alldata = @()
               $stats = Get-Stat -Entity $Server -Realtime -Stat $metrics -MaxSamples 1
               $stats | Group-Object -Property Entity | %{
                    $hoststat = "" | Select Date, HostName, VMName, CPUAvg
                    $hoststat.Date =Get-date
                    $hoststat.HostName = $_.name
                    $cpu = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property value -Average
                    $hoststat.CPUAvg = [int]$cpu.Average
                    $hostname = $hoststat.HostName
                    $alldata += $hoststat
               }
 
               $stats = Get-Stat -Entity $vms -Realtime -Stat $metrics -MaxSamples 1 
               $stats | Group-Object -Property Entity | %{
                    $vmstat = "" | Select Date, HostName, VmName, CPUAvg
                    $vmstat.Date = Get-date 
                    $vmstat.VmName = $_.name
                    $cpu = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property value -Average
                    $vmstat.CPUAvg = [int]$cpu.Average
                    $vmstat.HostName = $hostname
                    $alldata += $vmstat
               }
               $alldata | Export-Csv "c:\tmp\$Server.csv" -Append -noTypeInformation
               Clear-Variable -Name alldata
               Start-Sleep -s 10
          }
          Disconnect-VIServer * -Force -Confirm:$false
     } -ArgumentList ($Server, $metrics, $counter)
}
 


Concerning

Sponge cake

You can avoid the CSV file by using the Out-DataTable and functions of writing-DataTable .

Which also avoids having to use the LogParser utility.

Something like this should do the trick.

$dt = $alldata | Out-DataTable Write-DataTable -ServerInstance "localhost" -Database "CPUStats" -TableName "CPUusage" -Data $dt

Note that this will not add to the data in table CPUusage .

A possible solution is to read data from SQL before collecting the new metric values.

Tags: VMware

Similar Questions

  • I have a problem, try to uninstall the ask toolbar. get the error message: cannot access the VB script... need help please

    I have a problem, try to uninstall the ask toolbar. get the error message: unable to access the VB script... need help

    Hello

    How do you try to uninstall the toolbar?

    I would suggest trying the following methods and check if it helps.

    Method 1:

    Try the steps in the following Microsoft article and check if it helps.

    How to fix script errors in Internet Explorer on Windows computers:

    http://support.Microsoft.com/kb/308260

    Correction of errors in Internet Explorer: http://support.microsoft.com/kb/822521

    Method 2:

    Try to uninstall the toolbar, programs and features and check if it helps.

    Uninstall or change a program:

    http://Windows.Microsoft.com/en-us/Windows-Vista/uninstall-or-change-a-program

    Hope the information is useful.

  • Possibilities of the CPU usage data collection

    I'm trying to query CPU usage data in Virtual center 2.5 update 4, SQL server 2005, I can see via the performance tab, but is there another tool? If so they are Vmware tools or are they of the 3rd party tools? I can get suggestions please.

    Here is a link to the VI Toolkit (for Windows) Forum, where you can download what is necessary.

  • Need help optimizing Image size

    Hello... I am new to photoshoping...

    I need help help here...

    I'm working on a J2me application that uses the image of the map, since mobile phones have limited resources, I need to reduce the size of a map image as much as possible

    BUT the quality of the text (names of road) and roads must be preserved...

    Because they must be readable in mobile phone...

    So, what choices do I have?

    It has probably been used only 2 colors. This always proud image for allure, you will need 4 colors with the Color Table value adaptive or Perceptive to get a 288KO file (don't use not selective, it works well with this image). You can also try the application filter-> blur-> blur of Surface with a radius of about 25 and a threshold of 30 to simplify the picture. After you apply the Surface blur, the picture came out to about 268kb

    Edit: Scratch that I had my value 268kb with the size of the image intact

  • Script working but need help tweaking

    Add-pssnapin VMware.VimAutomation.Core

    # Set the user name and password
    $cred = get-VICredentialStoreItem - e:\powershell\cred2 file


    # Configuration connecting to VIServer
    to connect-VIServer-Server $cred. Home - user $cred. Username-password $cred. Password

    # Set the Date time and name of the file
    $date = get-date
    $datefile = get-date - uformat ' %m-%d - %Y '
    $filename = "E:\Powershell\Stage_patching_list_" + $datefile + ".csv".

    # Create list of servers to patch
    $report = @)
    Get-file DOSSIER0, Folder1, Folder2, Folder3. Get - VM | %{
    $vm = $_ | Get-View
    $row = "" | Select name, State, status, host, CPU_Allocated, RAM_Allocated, LastReboot, LastPatchApplied, restarted, questions
    $row. Name = $_. Name
    $row. State = $_. PowerState
    $row. Status = $vm. Summary.OverallStatus
    $row. Host = $_. VMHost
    $row. CPU_Allocated = $_.numcpu
    $row. RAM_Allocated = $_.memorymb
    $LastBoot = [System.Management.ManagementDateTimeConverter]: ToDmtfDateTime ((get-WmiObject win32_operatingsystem-ComputerName $row..)) LastBootupTime name))
    $row. LastReboot = $LastBoot
    $LastPatch = get-WmiObject Win32_QuickFixEngineering - ComputerName $row. Name |? { $_. InstalledOn} | Sort installedon | Select - last # 1 | FT hotfixid, installedon
    $row. LastPatchApplied = $LastPatch
    $row. Restarted = "YES/NO".
    $row. Questions = "YES/NO".
    $report += $row
    }

    # End of the Session on the server
    disconnect-viserver-confirm: $false

    # Creat file separated from Coma
    $report | Export-Csv $filename - NoType-Force

    # Create the e-mail message
    $server = "mail.xata.com".
    $port = 25
    $to = 'somebody @somewhere.com'.
    $from = Server@somewhere.com
    $subject = "list of servers to patch of scene.
    $body = "If you please see the attached file. TEXT TEXT TEXT TEXT.
    $message = New-Object system.net.mail.MailMessage $from, $to, $subject, $body

    # Create SMTP client
    $client = New-Object system.Net.Mail.SmtpClient $server, $port

    # Try to send the message
    try {}
    $message. IsBodyHTML = $true
    $attachment = new-object Net.Mail.Attachment ($filename)
    $message.attachments.add ($attachment)

    # Send message
    $client. Send ($message)
    }

    # Catch failed message
    catch {}
    "Exception caught in CreateTestMessage1():
    }

    The script works when I run it manually (comment out the snap) but I see errors of authentication on the cli. Especially the "Get-WmiObject: access denied." (Exception from HRESULT: 0 x 80070005 (REFUSAL of E_ACCESS)) "error. However the CSV fills all information as if there was no error at all. We would like to have this race on a scheduler for our patch dates. I wonder if the mistakes that showup in powerCLI will prevent a scheduled task to complete? Also is there a way to fix those problems, we run the script as a user with local administrative privileges on the servers the script controls. I tried - authentication 6 - enableallprivaleges and a crowd of other google answers. None of them have corrected the problem. However its confusing that it always returns the correct information.

    Is there a better way to do it? Is there a cleaner way to encode the script? Is last question possible to change the output of "Get-WmiObject Win32_QuickFixEngineering. - ComputerName $row Name |? { $_. InstalledOn} | Sort installedon | Select - last # 1 | "" hotfixid ft, installedon ' of '.

    \\Server\root\cimv2:Win32_QuickFixEngineering.HotFixID="KB2624667",ServicePackInEffect="SP3"to something a bit more readable like "Latest Patch = KB2624667"? We don't need the service pack information.

    I've tinkered with that many other scripts into a workable script that does what we want, I wonder if there is a way to clean. Thanks for looking and taking the time to answer.

    I dug a little deeper, and it seems that the InstalledOn property is different on a Windows 2008 host compared to a Windows 2003 or Windows 2008 R2 host.

    This led me to the following code.

    # Create Server List for Patching $report = @()
    foreach($vm in Get-VM){
        $row = "" | Select Name, State, Status, Host, CPU_Allocated, RAM_Allocated, LastReboot, LastPatchApplied, LastPatchDate, Rebooted, Issues
        $row.Name = $vm.Name
        $row.State = $vm.PowerState
        $row.Status = $vm.ExtensionData.Summary.OverallStatus
        $row.Host = $vm.VMHost
        $row.CPU_Allocated = $vm.numcpu
        $row.RAM_Allocated = $vm.memorymb
        $row.LastReboot = [System.Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject win32_operatingsystem -cn $row.Name).lastbootuptime)
        $lastPatch = Get-WMIObject Win32_QuickFixEngineering -ComputerName $row.Name |
            where {($_.psBase.properties["InstalledOn"].Value).Length -gt 0} |
            Sort-Object -Property {
                if($vm.Guest.GuestId -eq "WinLonghornGuest"){
                    $_.InstalledOn
                }else{
                    [datetime]($_.psbase.Properties["InstalledOn"].Value)
                }
            } |
            Select -Last 1    $row.LastPatchApplied = $lastPatch.HotfixId
        if($vm.Guest.GuestId -eq "WinLonghornGuest"){
            $row.LastPatchDate = $lastPatch.InstalledOn
        }
        else{
            $row.LastPatchDate = $lastPatch.psbase.Properties["InstalledOn"].Value
        }
        $row.Rebooted = "YES/NO"    $row.Issues = "YES/NO"    $report += $row}
    $report # End the Session on the Server
    

    If it is a Windows 2008 Server, the date is there in clear text for Windows 2003 and Windows 2008 R2, to use the trick of PSBase.

    On the Sort-Object, I use a codeblock to set the sort value, and in there, I can test what OS we are dealing with.

    In the same way I fill the $row. Property of LastPatchDate.

  • 1st time scripter... needs help with conditional step 2

    Never write the script in any form. JavaScript can be Cuniform as far as I know.

    Really want to understand such things.

    Download all guides... they make my head ache. Would like any suggestions on a good starting book. entry level stuff.

    Should I go to learn Javascript, then it'll all be easier?

    This is the purpose of the script that I want to write.

    I have a folder folders containing main/artist name/backup / retouched / * this is the lie of the images *.

    also / intact / * this is the lie of the images *.

    I would like to write a script that sends Photoshop thanks to all subfolders looking for files.

    Open the file.

    Determine if the file is grayscale.

    If this isn't the case, close the file.

    If grayscale determine the longest side of the image and resize it to 300 DPI maintaining proportions making long side 10 inches.

    Save the file in the folder '_8x10' file name added

    Save the file in "' C: / getty /" add "_8x10" file name "

    Close the file without saving changes

    OTHER IMPORTANT FACTS

    Emphasizing the need that the originals should not be harmed in any way.

    99% of the files are .tiffs others would jpg - I can't ignore jpg files in order to remove a variable.

    I worked on it for 2 days, trying to teach me, and it is not just by clicking. I can't pick it up quickly.

    Here's what I wrote and tried to patch all of the other scripts on the web in the hope that I understood why I was picking up this code.

    I'm short on time and would like advice on this.

    Here is my code:

    GrayscaleThenLandOrPortTo10Inches300dpi.jsx

    Copyright 2012

    Written by Brian Shupe steal shamelessly on the net

    /*

    Description:

    This script finds the folder and all subfolders for images.

    Check to see if they are grayscale

    If so, he trims the long side at 10 inches at 300 dpi

    */

    turn on double click of the

    Macintosh Finder or Windows Explorer

    #target photoshop

    Make Photoshop the frontmost application

    where we double clicked on the file

    app.bringToFront ();

    ///////////////////////////

    //       SET-UP          //

    ///////////////////////////

    Close all open documents

    so that {(app.documents.length)

    app.activeDocument.close)

    }

    Create the dialog select parent folder

    var imageFolder is Folder.selectDialog ("select a folder with images to treat");.

    Set variables naming for easier coding

    var doc = app.activeDocument;

    set the units to inches

    Save current preferences

    var strtRulerUnits = app.preferences.rulerUnits;

    var strtTypeUnits = app.preferences.typeUnits;

    Adobe Photoshop CS4 use pixels and display without the value dialog boxes

    app.preferences.rulerUnits = Units.INCHES

    app.preferences.typeUnits = TypeUnits.INCHES

    app.displayDialogs = DialogModes.NO

    Recursively process all subfolders

    If (image! = null) processFolder (imageFolder);

    function processFolder (folder) {}

    List of files of the var = folder.getFiles)

    for (var i = 0; i < fileList.length; i ++) {}

    var file = list of files [i];

    }}

    Check if the active document isn't in grayscale. If this is true do nothing

    If (doc.mode! = DocumentMode.GRAYSCALE) {}

    } else

    Check if the document is higher than it is wide

    If (doc.height > doc.width)

    {

    Perform this action if the IF statement is true. Action of sizes both height to 10 inches and 300 DPI

    doAction ("Port", "Getty");

    }

    on the other

    {

    Perform this action if the IF statement is false. Action sizes two length of 10 inches and DPI to 300

    doAction ("Land", "Getty");

    }

    Create a folder to contain a file duplicate

    myFolder var = new Folder("c:/Getty/");

    myFolder. Create();

    saveFile = new file ("C: / Getty /' + imgName +"_"+"8 x 10")

    var CurrentFolder = activeDocument.path;

    var ParentFolder = decodeURI (activeDocument.path.parent);

    saveFile = new file (parentFolder + ' /' + 'CONTAINER BACKUP' + ' /' + imgName + "_" + "8 x 10")

    app.activeDocument.close (SaveOptions.DONOTSAVECHANGES)

    I think that, right now, the problem is when it gets to the point where he seeks an image open... There are jumps to zero and it.

    Anyone can see that for my clumsy attempt and course correct me?

    would be happy to discuss tutoring services.

    This is a full version that could help with all of the necessary steps...

    #target photoshop
    app.bringToFront();
    main(); //call the main function
    function main(){
    var folders =[];
    var topLevel = Folder.selectDialog("Please select top level folder");
    if(topLevel == null) return; //if cancelled quit
    folders = FindAllFolders(topLevel, folders);
    folders.unshift(topLevel);
    var outputFolder = Folder("/c/Getty/");
    //create output folder if it does not exist
    if(!outputFolder.exists) outputFolder.create();
    for(var z in folders){// loop through all subfolders
    var fileList = folders[z].getFiles("*.tif"); //get a list of all tifs in this folder
    for(var a in fileList){//loop through all files in folder
        app.open(fileList[a]);//open file
        var doc = activeDocument;
        if(doc.mode != DocumentMode.GRAYSCALE){//if not greyscale close and get next doc.
            doc.close(SaveOptions.DONOTSAVECHANGES);
            continue;
            }
        if(doc.width > doc.height){//landscape
            //resize document, only one value is required otherwise it might distort the document.
            doc.resizeImage(new UnitValue(10,'in'), undefined, 300, ResampleMethod.BICUBIC);
            }else{//portrait
                doc.resizeImage(undefined, new UnitValue(10,'in'), 300, ResampleMethod.BICUBIC);
                }//end resize
            //get the name without the .tif extension
            var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
            //create the output file path and name
            var saveFile = File(outputFolder + "/" + Name + "_8x10.tif");
            //save and close
            SaveTIFF(saveFile);
            doc.close(SaveOptions.DONOTSAVECHANGES);
        }//end filelist
    }//end folders
    }//end main function
    function FindAllFolders( srcFolderStr, destArray) {
     var fileFolderArray = Folder( srcFolderStr ).getFiles();
     for ( var i = 0; i < fileFolderArray.length; i++ ) {
      var fileFoldObj = fileFolderArray[i];
      if ( fileFoldObj instanceof File ) {
      } else {
             destArray.push( Folder(fileFoldObj) );
      FindAllFolders( fileFoldObj.toString(), destArray );
      }
     }
     return destArray;
    }
    function SaveTIFF(saveFile){
    tiffSaveOptions = new TiffSaveOptions();
    tiffSaveOptions.embedColorProfile = true;
    tiffSaveOptions.alphaChannels = true;
    tiffSaveOptions.layers = true;
    tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
    activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
    }
    
  • HARD drive is full, but only be able to view the OS, applications and data. Need help to find out what else takes place.

    I am running a Compaq nx 7400 and Windows Vista Business edition. My HARD drive is 66.6 GB. PROG 7.63 files. Windows 9.61. 19.3 user data. 36.54 total.
    But my HARD disk is apparently full of 98.7 percent. Where the other GB 30.1? Recycle bin isempty and deleted temporary files.
    I want to upgrade to Win 7, but do not have the space.
    Can someone help me, please!

    Hello Falcodriver,

    Thanks for the return of the answer!  I have included a link below with a similar question.  It could be the system restore or backups that use the extra space.  I hope this link helps!

    Microsoft Answers:

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-hardware/hard-drive-is-full-and-i-Don ' t-know-why/83b620da-c029-4a1b-81cd-0b166b008162

    Thank you

  • Playlists and data cards, need help.

    Is it possible to put a playlist on a memeory card and have this playlist appear in the menu of the music with the internal playlists? I have a v1 e260 as well as a 2 GB card... I made a playlist and tried to put it on the memory card in msc mode. The music is on the map, but not in a playlist. The music is presented as individual albums.

    It seems pretty stupid to not be capable of this. I'm not a fan of just drag / drop off willy nilly.

    Since you have a player of v1, you can use playlists format .pla and even combine music card and memory in a single playlist if you want to.

    The key that you have to remember is:

    Go PLA playlists in the PLAYLISTS folder on your drive (not on your map)

    Make playlists m3u NOT go in the folder SELECTIONS. This format requires that you put them in the MUSIC folder along with your music. With this format, you must make separate lists for the internal memory and the card. They are not cumulative in a playlist. So, if you create a music .m3u playlist on your map then Yes, you store this list on the map as well.

    When you view the playlists menu on your player, if you have a .m3u playlist on your card, it is designated by the small icon to the left of the title playlist showing whether they are on the memory card, just like with the songs.

    I hope this helps.

  • final verification of source/target with lots of data discrenpcy - need help urgent

    We rank target counties and source, many tables are not synchronized.

    Information Replicat has not shown a lot of mistakes. everyghing is running.

    How can I find out where the problems are?

    Help, please.

    Please look into this document.

    Dbms_xmlstore... InsertXML give Ora-01008 for Clob column with null [ID 1270580.1]

  • [AS] Script does not - need help

    I tried every possible means to create a shade and use it as the fill color of a selection, but no matter what I try, it doesn't work. Here is my last attempt:

    Tell application "Adobe InDesign CS5"
    the value wiilibrary to the library 'template.indl Wii. "
    Set myDocument to the active document
    the value mycolorindicator to place the element element "column spinal indicator lang" of myDocument wiilibrary
    Set mySelection to select mycolorindicator
    mySelection set selection
    the value mySpread spread active of the active window
    the value myPageItem to article 1 of mySelection
    the colorname to «Spanish3» value
    languagevalue value {0, 10, 10, 10}
    Set name of colors colorTest

    the value of New_Swatch to make the color with properties {name: colorname, color: CMYK, color value: model languagevalue: process}
    set the fill color of myPageItem to New_Swatch

    tell the end

    Error I get is:

    error "Adobe InDesign CS5 has been an error: invalid value for set property 'fill color'.» Expected or string, but received color swatch. "number 30477

    You need make the color in the document, not the application. And "color: CMYK" should probably be "space: CMYK.

  • My car game needs help (swf in the post)

    Hello
    I have a car that I control with the arrow keys and I want the car to pull to the side when you press space.
    I have a picture of the hunters flash to png format that appears in the same place of the car even when I move the car to the right or left etc.

    The scene is seen from above.

    And for some reason the first flash of hunters is always slow when you hold the space key.

    It's here
    Caliber400.webs.com/car_game.swf

    Please do not move the car while testing the push function at the same time.

    This is the script that I need help.

    Sorry for my English.

    (will post if necessary fla).

    Have the muzzle flash as part of the drive to movieclip so that it moves with the car. Instead of moving out of sight in box 1, just do not have in frame 1.  Alternatively, instead of having two chassis as a movieclip, you could control its _visible property and avoid using a mount command to change the mounts.  Sometimes a change of framework can get delayed if there are a lot of things that could be happening when you say that it's slow.

  • Need help with understanding PowerCli scripting by LucD

    Hello

    I'll give you the standard statement that I am a noob powercli and don't really know what I'm doing here.  Here's a script that works because it runs without error and gives a report but I need help to understand this under his weight.

    Connect-VIServer '< our vcenter >' - user < user > admin-password < admin-user-pwd >

    $allvms = @)

    $vms = get - Vm | where {$_.} PowerState - eq "Receptor"}

    $start = (get-Date). AddDays(-1)

    $metrics = "mem.usage.average".

    $stats = get-Stat-entity $vms - start $start - Stat $metrics

    $stats | Group-object - property {$_.} Timestamp.Day}, {$_.} @entity.name} | %{

    $vmstat = "" | Select the day, MemAlloc, MemMin, MemMax, MemAvg, VmName

    $vmstat. VmName = $_. Values [1]

    $vmstat. Day = $_. Group [0]. Timestamp.Date

    $mem = $_. Group | where {$_.} MetricId - eq "mem.usage.average"} | Measure-object-property value - average - Maximum - Minimum

    $vmstat. MemMax = [int] $mem. Maximum ##dfsdf

    $vmstat. MemAvg = [int] $mem. Average

    $vmstat. MemMin = [int] $mem. Minimum

    $vmstat. MemAlloc = $_. Group [0]. Entity.MemoryMB

    $allvms += $vmstat

    }

    $allvms |

    Export-Csv "c:\ < folder > \ <>.csv file Destination"-noTypeInformation

    It connects to our server vcenter server and offers two days of data.  Today and yesterday, all with a timestamp of 0:00.  See below for an example of a virtual machine.

    VmNameDayMemAllocMemMaxMemAvgMemMin
    < name VM1 >07/05/2016 0:004096181818
    < name VM1 >06/05/2016 0:0040963612

    8

    The MemMax, the MemAvg and the MemMin are for this day?  Just the max of this period of sampling time 0:00?

    What I'm looking for, it is to find that the use of the maximum memory of virtual machines are for the whole day.  So I hope that I can remove memory of VMs that do not use it.  I was listed on the change $start = (Get-Date). The value of AddDays(-1) to $start = (Get-Date). AddDays(-30) and see what things alike.  I want to be sure however that the value for MemMax is the highest value for a period of 24 hours.  That is to say for the 07/05/2016 the given virtual machine never used a maximum of 18% of his memory attributed the 06/05/2016 the maximum amount of memory used was 36%, and so on that I extend on the date range.

    Kind regards

    Michael

    It then becomes a rather simple Get-Stat script.

    $vms = get - Vm | where {$_.} PowerState - eq "Receptor"}

    $start = (get-Date). AddDays(-1)

    $metrics = "mem.usage.average".

    Get-Stat - entity $vms - start $start - Stat $metrics |

    Select Timestamp,@{N='VM'; E={$_. @entity.name}}, Value |

    Tri-objet-VM property |

    Export-Csv "c:\------.csv '-noTypeInformation

  • Need help with Oracle SQL merge records according to date and term dates

    Hi all

    I need help to find this little challenge.

    I have groups and flags and effective dashboards and dates of term against these indicators according to the following example:

    GroupName Flag_A Flag_B Eff_date Term_date
    Group_ATHERETHERE2011010199991231
    Group_ANN2010010120101231
    Group_ANN2009010120091231
    Group_ANN2006010120081231
    Group_ANTHERE2004010120051231
    Group_ATHERETHERE2003010120031231
    Group_BNTHERE2004010199991231
    Group_BNTHERE2003010120031231

    As you can see, group_A had the same combination of (N, N) flag for three successive periods. I want to merge all the time periods with the same indicators in one. Where entry into force will be the most early (underlined) time period and end date will be later (underlined)

    So the final result should look like this:

    GroupName Flag_A Flag_B Eff_date Term_date
    Group_ATHERETHERE2011010199991231
    Group_ANN2006010120101231
    Group_ANTHERE2004010120051231
    Group_ATHERETHERE2003010120031231
    Group_BNTHERE2003010199991231

    Thanks for your help

    Here's the DDL script

    drop table TMP_group_test;

    create table TMP_group_test (groupname varchar2 (8))

    , flag_a varchar2 (1)

    , flag_b varchar2 (1)

    , eff_date varchar2 (8)

    , term_date varchar2 (8)

    );

    insert into TMP_group_test values ('Group_A', 'Y', 'Y', ' 20110101 ', ' 99991231');

    insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20100101 ', ' 20101231');

    insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20090101 ', ' 20091231');

    insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20060101 ', ' 20081231');

    insert into TMP_group_test values ('Group_A', 'n', 'Y', ' 20040101 ', ' 20051231');

    insert into TMP_group_test values ('Group_A', 'Y', 'Y', ' 20030101 ', ' 20031231');

    insert into TMP_group_test values ('Group_B', 'n', 'Y', ' 20040101 ', ' 99991231');

    insert into TMP_group_test values ('Group_B', 'n', 'Y', ' 20030101 ', ' 20031231');

    commit;

    Post edited by: user13040446

    It is the closest, I went to the solution


    I create two rows;

    Rnk1: partition by group name, order of eff_date / / desc: this grade will sort the records of the most recent and handed to zero for each group\

    Rnk2: (dense) partition by group name, flag_A, flagb: this grade for each combination of group\flag gives a number so that they are classified as "families".

    Then I use the function analytic min

    Min (eff_date) more (partition of GroupName, rnk2): the idea is that, for each Member of the same family, the new date is the min of the family (and the max for the date of the term), at the end I just need separate so that the duplicates are gone

    Now the problem. As you can see from the query below, records of 1 and 6 (as identified by rownum) are identified in the same family, because they have the same combination of flag, but they are not successive, so everyone must keep its own date of entry into force.

    If only I can make the distinction between these two that would solve my problem


    Query:


    Select rowNum,GroupName, flag_a, flag_b, eff_date, term_date, rnk1, rnk2

    , min (eff_date) more than (partition by GroupName rnk2( ) min_eff

    Of

    (

    Select rowNum,

    GroupName , flag_a , flag_b , eff_date , term_date

    rank() more than (partition by GroupName stopped by eff_date desc) rnk1

    DENSE_RANK() more than (partition by GroupName order by flag_A flag_B ( ) rnk2

    de dsreports . tmp_group_test

    ) order by rowNum

    Hello

    user13040446 wrote:

    Hi KSI.

    Thanks for your comments, you were able to distinguish between these lines highlight, but lost lines 2,3,4 which are supposed to have the same date min = 20060101.

    Please see the table wanted to see the final result I want to reach

    Thanks again

    This first answer is basically correct, but in the main query, you want to use the function MIN, not the analytical function aggregation and GROUP BY columns with common values, like this:

    WITH got_output_group AS

    (

    SELECT GroupName, flag_a, flag_b, eff_date, term_date

    ROW_NUMBER () OVER (PARTITION BY GroupName

    ORDER BY eff_date

    )

    -ROW_NUMBER () OVER (PARTITION BY GroupName, flag_a, flag_b)

    ORDER BY eff_date

    ) AS output_group

    OF tmp_group_test

    )

    SELECT GroupName, flag_a, flag_b

    MIN (eff_date) AS eff_date

    MAX (term_date) AS term_date

    OF got_output_group

    GROUP BY GroupName, flag_a, flag_b

    output_group

    ORDER BY GroupName

    eff_date DESC

    ;

    The result I get is

    GROUP_NA F F EFF_DATE TERM_DAT

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

    Group_A Y 20110101 99991231 Y

    N Group_A 20101231 20060101 N

    Group_A N 20051231 20040101 Y

    Group_A Y Y 20031231-20030101

    Group_B N Y 99991231 20030101

    which is what you asked for.

  • Need help to do the job of script Get-FolderPath

    Hello world

    I have do this script work can someone help me on this. I was able to produce the csv file unfortunately there is no value/output on the path column. I think that I was not able to call the function get-folderpath correctly. Thank you.

    ------

    $date = get-Date-format-M - d - yyyy

    . 'c:\Users\Get-FolderPath.ps1 '.

    $folders = get-file-type vm | Get-FolderPath | Sort-Object Id

    {Set-Path function

    Param ($Object)

    foreach ($folder IN $folders) {}

    If ($folder. ID - eq $Object.Id) {}

    $result = $folder. Path

    breaking

    }

    }

    $result

    }

    Get - VM | Sort-Object FolderID | Select name, Uid, NumCpu, MemoryGB, ProvisionedSpaceGB, @{N = "Path"; E = {Set-path - object $_.} Folder}}, ResourcePoolId, ResourcePool, @{N = "ToolsStatus"; E={$_. ExtensionData.Summary.Guest.ToolsVersionStatus}} | `

    Export-Csv "C:\test\vm-vServer-$date.csv" - NoTypeInformation - UseCulture

    -----------

    Also when I try to run it directly on powercli I get this error

    --------

    scripts\Get - FolderPath.ps1:45 tank: 25

    + $fld = get-view $fld. Parent

    +                         ~~~~~~~~~~~

    + CategoryInfo: InvalidData: (:)) [Get-view], ParameterBindingVal)

    idationException

    + FullyQualifiedErrorId: ParameterArgumentValidationError, VMware.VimAutom

    ation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

    Get-view: could not validate the argument on the parameter "VIObject". The argument is

    NULL, empty or an element of the collection argument contains a null value.

    Provide a collection that does not contain any null values and then try him

    command again.

    ------

    I would like to get output something like that. The most important thing is for me to get the path of the folder location.

    The virtual computer name. Data Center | Cluster | NumCPU | MemoryGB | Implemented SpaceGB. Path of the folder.

    Thanks in advance.

    See you soon,.

    The following PowerCLI script will give you the information you want:

    Get - VM | Select-Object - property Name,@{N='Datacenter'; E={$_| Get-Datacenter}},@{N='Cluster'; E={$_. VMHost.Parent}},

    NumCPU,MemoryGB,ProvisionedSpaceGB,@{N='Path'; E={($_. Folder | Get - FolderPath). Path}}

  • Bike via script of paragraph styles - need help

    Hello

    I have a large document (potentially 3000 pages), on each page is a picture of a picture frame and inside each image is a famous quote. I need to type in each quote so I have 10 configuration value different paragraph styles in a different font. I need a script that applies "QuoteStyle1" the text on the first page, "QuoteStyle2" on the next page, etc., and once that 'QuoteStyle10' has been applied the script performs a loop and continues to scroll through the styles apply a style that is different on each page, until it reaches the end of the document.

    I got a start on the script (see image), but I think the problem is the line 11 - I want to run the script without having to select anything.

    Some additional info that may or may not be of use - all quotes are drawn from a data merge. There is also a name and a color from the data merge. The background on each frame is a different color and that is created with the a very large 'rule below' in a number of other paragraph styles. They are applied with a 'Find & ReplacebyList' i.e. find replace 'Red' with the paragraph style "ColourRed. In the script, I tried to ignore these "color" paragraph styles (lines 2-9) is only the 'quote' styles that the effects of the script.

    Any help getting this race would be more useful.Screen Shot 2015-07-15 at 10.01.20.png

    First of all congratulations for the very creative use of blending modes. I would have never thought about it by myself.

    Now, for the script, here are two ways to do it (both enjoy the fact that you use a paragraph style BaseQuote):

    (1) use a grep search:

    var doc=app.activeDocument;
    var baseQ=doc.paragraphStyles.item('BaseQuoteStyle');
    var switchToStyles=[
    'QuoteStyle1',
    'QuoteStyle2',
    'QuoteStyle3',
    'QuoteStyle4',
    'QuoteStyle5',
    'QuoteStyle6',
    'QuoteStyle7',
    'QuoteStyle8',
    'QuoteStyle9',
    'QuoteStyle10'];
    var l=switchToStyles.length;
    app.findGrepPreferences=app.findChangeGrepOptions=null;
    app.findGrepPreferences.appliedParagraphStyle=baseQ;
    app.findChangeGrepOptions.includeMasterPages=false;
    var quotes=doc.findGrep();
    for (var i=0; i
    

    (2) scroll all managers of related texts:

    var doc=app.activeDocument;
    var baseQ=doc.paragraphStyles.item('BaseQuoteStyle');
    var pags=doc.pages.everyItem().getElements();
    var switchToStyles=[
    'QuoteStyle1',
    'QuoteStyle2',
    'QuoteStyle3',
    'QuoteStyle4',
    'QuoteStyle5',
    'QuoteStyle6',
    'QuoteStyle7',
    'QuoteStyle8',
    'QuoteStyle9',
    'QuoteStyle10'];
    var l=switchToStyles.length;
    for (var p=0;p		   

Maybe you are looking for