How can we create SSAS 2008 cube partitions using Powershell?
This adds a partition to the Adventure Works DW 2008R2 cube (specifically the Internet Customers measure group in the Adventure Works cube):
$server_name = "localhost"
$catalog = "Adventure Works DW 2008R2"
$cube = "Adventure Works"
$measure_group = "Fact Internet Sales"
$old_partition = "Customers_2004"
$new_partition = "Customers_2009"
$old_text = "'2008"
$new_text = "'2009"
[Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.AnalysisServices.DLL")
$srv = new-object Microsoft.AnalysisServices.Server
$srv.Connect("Data Source=" + $server_name)
$new_part = $srv.Databases[$catalog].Cubes[$cube].MeasureGroups[$measure_group].Partitions[$old_partition].Clone()
$new_part.ID = $new_partition
$new_part.Name = $new_partition
$new_part.Source.QueryDefinition = $new_part.Source.QueryDefinition.Replace($old_text, $new_text)
$srv.Databases[$catalog].Cubes[$cube].MeasureGroups[$measure_group].Partitions.Add($new_part)
$srv.Databases[$catalog].Cubes[$cube].MeasureGroups[$measure_group].Partitions[$new_partition].Update()
$srv.Databases[$catalog].Update()
$srv.Disconnect()
You'll have to change variables up top, and the reference to the Microsoft.AnalysisServices.dll assembly, but other than that, this will work peachy keen.
The trick is to call Update() on the object changed and then on the whole database itself.
If you'd like to process the new partition, as well, you can do that with the following line before $srv.Disconnect:
$srv.Databases[$catalog].Cubes[$cube].MeasureGroups[$measure_group].Partitions[$new_partition].Process()
You can learn more about Analysis Management Objects (AMO) here.
Check out this: PowerSSAS
It doesn't have explicit add partition support, so you'll probably have to craft an XMLA snippet to do the add partition and then use PowerSSAS to push it to the SSAS server.
you can use :
Microsoft.AnalysisServices.Deployment [ASdatabasefile]
{[/s[:logfile]] | [/a] | [[/o[:output_script_file]] [/d]]}
to deploy your cube AS with powershell.
Related
I´m quite new to PowerShell and just a bit more experienced with programming as such.
The goal of the current excercise our teacher gave us, is basically to code a simple crossroads traffic light.
I use Windows Forms to display labels, that change colors.
Now I coded a button, that is supposed to run through the traffic light "phases" once.
Thanks to prior experiences I went with the method to have a incrementing variable and a Function that checks the value of said variable.
But the colors turn the intended way once every 4 tries or so, without a recognizable logic to it.
Am I missing something basic in the way PS reads code and the timing thereof?
Button, supposed to reset the variable, then increment it, then call the function. Due to the Write-Host I can at lease say that the variable does count to 4 as intended
$Button1 = New-Object System.Windows.Forms.Button;
$Button1.Location = New-Object System.Drawing.Size(300,100);
$Button1.Text = "Next Phase";
$Window.Controls.Add($Button1);
$Button1.Add_Click({
#Set Phase 0, then increment & update Function Phase
$current_phase = 0;
Do {
$current_phase++;
Write-Host $current_phase;
Phase_update;
} Until($current_phase -gt 3)
Two of the functions minus some of the color changes, intended to change the colors and then wait a while
Function Phase_update
{
#Phase A
if ( $current_phase -eq 1 )
{
$LightTop.ForeColor = 'red';
}
#Phase B
elseif ( $current_phase -eq 2 )
{
$LightTop.ForeColor = 'green'
}
Start-Sleep -Seconds 2
}
# Show Form
[void]$Window.ShowDialog()
Thanks in advance for any input, problem specific and in general
I am creating a Aggregation connector though Add-In. I am able to create the connector without Strong target end point by using the below mentioned code.
EA.Connector connector = signalEle.Connectors.AddNew("", "Aggregation");
connector.SupplierID = parentElement.ElementID;
connector.Subtype = "Strong";
connector.StyleEx = "LFEP=" + strEleName.AttributeGUID + "L;";
connector.ClientEnd.Role = strEleName.Name;
connector.Update();
How to create the connector with Strong target end ?
EA strikes again. Instead of setting subType to "Strong" you need to do this:
ce = connector.clientEnd;
ce.Aggregation = 2;
ce.Update();
Or if vice versa use supplierEnd instead. The subType seems to be ignored in this case.
I'm interested in creating an edge (u,v) between two nodes of the same class in a graph if they share the same day of year and v.year = u.year+1.
Say I have vertices.csv:
id,date
A,2014-01-02
B,2015-01-02
C,2016-01-02
D,2013-06-01
E,2014-06-01
F,2016-06-01
The edge structure I'd like to see would be this:
A --> B --> C
D --> E
F
Let's set the vertex class to be "myVertex" and edge class to be "myEdge"? Is it possible to generate these edges using the SQL interface?
Based on this question, I started trying something like this:
BEGIN
LET source = SELECT FROM myVertex
LET target = SELECT from myVertex
LET edge = CREATE EDGE myEdge
FROM $source
TO (SELECT FROM $target WHERE $source.date.format('MM-dd') = $target.date.format('MM-dd')
AND $source.date.format('yyyy').asInteger() = $target.date.format('yyyy').asInteger()-1)
COMMIT
Unfortunately, this isn't correct. So I got less ambitious and wanted to see if I can create edges just based on matching day-of-year:
BEGIN
LET source = SELECT FROM myVertex
LET target = SELECT from myVertex
LET edge = CREATE EDGE myEdge FROM $source TO (SELECT FROM $target WHERE $source.date.format('MM-dd') = $target.date.format('MM-dd'))
COMMIT
Which still has errors... I'm sure it's something pretty simple to an experienced OrientDB user.
I thought about putting together a JavaScript function like Michela suggested on this question, but I'd prefer to stick to using the SQL commands as much as possible for now.
Help is greatly appreciated.
Other Stack Overflow References
How to print or log on function javascript OrientDB
I tried with OSQL batch but I think that you can't get what you want.
With whis OSQL batch
begin
let a = select #rid, $a1 as toAdd from test let $a1 = (select from test where date.format("MM") == $parent.$current.date.format("MM") and date.format("dd") == $parent.$current.date.format("dd") and #rid<>$parent.$current.#rid and date.format("yyyy") == sum($parent.$current.date.format("yyyy").asInteger(),1))
commit
return $a
I got this
but the problem is that when you create the edge you can not cycle on the table obtained in the previous step.
I think the best solution is to use an JS server-side function.
Hope it helps.
I've got a custom CloudWatch metric based on a historical value, so I'm publishing them with explicit timestamps. I've seen an issue using both the C# and PowerShell APIs where I don't see all my metrics right away.
In the example below, I'm creating sample points for every hour for the past two weeks, but I only see the last ~48 hours in my graph in the CloudWatch console.
Initialize-AWSDefaults
$cwNamespace = 'Historical CW Sanity Check'
# generate some data
$now = [DateTime]::Now.ToUniversalTime()
$startTime = $now - [TimeSpan]::FromDays(14)
$t = $startTime
$x = 0
while ($t -le $now)
{
$t += [TimeSpan]::FromHours(1)
$datum = New-Object -TypeName 'Amazon.CloudWatch.Model.MetricDatum'
$datum.Unit = [Amazon.CloudWatch.StandardUnit]::Count
$datum.Value = 2 * $x
$datum.Timestamp = $t
$datum.MetricName = 'Test 2'
$x +=1.0
Write-Host "($t, $x)"
Write-CWMetricData -Namespace $cwNamespace -MetricData $datum
}
From the docs, I thought it supported up to two weeks' worth of historical data. I'm wondering why I see the new points before the old points (or if the old points are going to show up at all). It looks like I'm only getting two days' worth.
From the help text on Write-CWMetricData:
Data that is timestamped 24 hours or more in the past may
take in excess of 48 hours to become available from submission time using
GetMetricStatistics.
I'm betting the same limit holds true for the graphs in the Console.
Very simple question. How do i get this string:
$endDate = "01/14/2088"
Some code here to tranform the current form of date into numbers which AD can accept.
Into $accountExpire which can be inserted via:
The Format is like this "129955896000000000" A big ass number.
$newUser.put(“accountExpire”, $accountExpire)
REMEMBER! It's Windows 2003r2 we are talking about.
Here is a way to solve it in PowerShell :
$endDate = "01/14/2088"
$dtEndDate = [datetime]::parse($endDate)
$ldtEndDate = $dtEndDate.ToFileTimeUtc()
$ldtEndDate
153693504000000000
You can download a tool called SlxWinDFI (sorry in french) that allow you to verify and to compute long date from calendar dans duration.