Tag: powershell

  • PowerShell – Adding a Dataset

    PowerShell – Adding a Dataset

    PowerShell Scripts for creating and adding a dataset, columns and table.

    Add PBIDataset
    
    New-PowerBIColumn ---- creates a column
    New-PowerBITable ----- creates a table
    New-PowerBIDataSet ---- creates a dataset
    Add-PowerBIDataset ----- adds a dataset
    
    
    $ is used to declare a variable
    
    Creating a Dataset
    
    PS C:\"your path here"> $col1 = new-powerbicolumn -Name Name -Datatype String
    >> $col2 = New-PowerBIColumn -Name ID -DataType Int64
    >> $col3 = New-PowerBIColumn -Name Gender -DataType String
    >> $table_primary = New-PowerBITable -Name main_table -Columns $col1,$col2,$col3
    >>
    >> $col4 = New-PowerBIColumn -Name ID -DataType Int64
    >> $col5 = New-PowerBIColumn -Name Date -DataType DateTime
    >> $col6 = New-PowerBIColumn -Name Detail -DataType String
    >> $col7 = New-PowerBIColumn -Name Result -DataType Double
    >> $table_secondary = New-PowerBITable -Name secondary_table -Columns $col4,$col5,$col6,$col7
    >>
    >> $dataset = New-PowerBIDataset -Name Meansh_Sample -Tables $table_primary, $table_secondary
    >>
    >> Add-PowerBIDataset -Dataset $dataset -WorkspaceId "provide workspaceID"
    
    
    {
    
    	$ is used to define a variable 
    	new-powerbicolumn --- inbuilt cmdlet
    	new-powerbitable --- inbuilt cmdlet
    	new-powerbidataset --- inbuilt cmdlet
    	
    	
    define a columns first, requires name and datatype
    
    define a table and required which columns will be part of it
    
    define a dataset and requires which tables will be part of it as well as the name of the data set 
    	
    	Finally do 
    
    Add-PowerBIDataset command and provide the id for the workspace ----- if no name is given then the dataset will be created in "MyWorkspace" 
    
    else if the name is provided then it will be a part of that workspace.
    	
    }	
    
    
     $col1 = New-PowerBIColumn -Name ID -DataType Int64
    >> $col2 = New-PowerBIColumn -Name Data -DataType String
    >> $table1 = New-PowerBITable -Name SampleTable1 -Columns $col1,$col2
    >> $col3 = New-PowerBIColumn -Name ID -DataType Int64
    >> $col4 = New-PowerBIColumn -Name Date -DataType DateTime
    >> $col5 = New-PowerBIColumn -Name Detail -DataType String
    >> $col6 = New-PowerBIColumn -Name Result -DataType Double
    >> $table2 = New-PowerBITable -Name SampleTable2 -Columns $col3,$col4,$col5,$col6
    >> $dataset = New-PowerBIDataSet -Name SampleDataSet -Tables $table1,$table2

  • Custom Scripts – Power Shell

    Custom Scripts – Power Shell

    One of my close friend had this discussion with me about how to get list of workspaces with certain conditions and how to get those details using PowerShell script. So this following script was written to get conditional workspaces and displaying them.

    While we were testing this, we realized that there was an error thrown due to number of calls the script was making. To handle that we can add start – stop as a gap timer to this to ensure there is no issue.

    $worksapces = Get-PowerBIWorkspace -Scope Organization -All
    
    Write-Host "Getting Workspaces"
    
    $groupnames = @()
    
    ForEach ($workspace in $worksapces) 
    {if ($workspace.Type -eq "PersonalGroup") { continue }
    if ($workspace.IsOnDedicatedCapacity) { continue }
    
    $reports = Get-PowerBIReport -WorkspaceId $workspace.Id  -Scope Organization
    
    if ($reports.Length -eq 0) { continue }
    
    if ($reports.Length -gt 0) {
        Write-Host "$($workspace.Name) - $($workspace.Type) - $($workspace.State) - $($workspace.IsOnDedicatedCapacity) - $($reports.Count)"
    }
    
    $exportWS = New-Object -TypeName PSObject -Property @{
        Name = $workspace.Name
        Type = $workspace.Type
        State = $workspace.State
        IsOnDedicatedCapacity = $workspace.IsOnDedicatedCapacity
        ReportCount = $reports.Count
    }
    $groupnames += $exportWS
    }
    $groupnames | Export-CSV "you_chosen_path_entire_path_is_needed.csv"
  • Powershell Commands

    Powershell Commands

    Following modules are available

    MicrosoftPowerBIMgmt — is the highest  level within this you can have following

    1.Admin

    2.Capacities

    3.Data

    4.Profile

    5.Reports

    6.Workspaces

    To get staretd

    Install-Module -Name MicrosoftPowerBIMgmt and then run the installation command for individual modules as needed