Last active
September 18, 2019 16:02
-
-
Save SQLvariant/d9e34d09364ccc859c4f51cb6e512cd6 to your computer and use it in GitHub Desktop.
a few helpful Argument Completers for common Power BI commands, you can ad to your $profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# We need an argument completer for -Workspace #> | |
Register-ArgumentCompleter -ParameterName Workspace -ScriptBlock { | |
Get-PowerBIWorkspace | ForEach-Object { | |
$CompletionText = $_.Name | |
New-Object System.Management.Automation.CompletionResult ( | |
"(Get-PowerBIWorkspace -Name '$($CompletionText)')", | |
$_.Name, | |
'ParameterValue', | |
"$_ (PowerBIWorkspace)" | |
) | |
} | |
}; | |
<# We need an argument completer for -WorkspaceID #> | |
Register-ArgumentCompleter -ParameterName WorkspaceID -ScriptBlock { | |
Get-PowerBIWorkspace | ForEach-Object { | |
$CompletionText = $_.Id | |
New-Object System.Management.Automation.CompletionResult ( | |
$CompletionText, | |
$_.Name, | |
'ParameterValue', | |
"$_ (PowerBIWorkspaceID)" | |
) | |
} | |
}; | |
<# We need an argument completer for -Report when -WorkspaceID has been specified. #> | |
Register-ArgumentCompleter -CommandName Copy-PowerBIReport -ParameterName Report -ScriptBlock { | |
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) | |
if ($fakeBoundParameter.ContainsKey('WorkspaceId')) { | |
Get-PowerBIReport -WorkspaceId $($fakeBoundParameter.WorkspaceId) | ForEach-Object { | |
$CompletionText = $_.Id | |
New-Object System.Management.Automation.CompletionResult ( | |
$CompletionText, | |
$_.Name, | |
'ParameterValue', | |
"$_ (PowerBIWorkspaceID)" | |
) | |
} | |
} | |
}; | |
<# We need an argument completer for -Id parameter of the Get-PowerBIWorkspace command #> | |
Register-ArgumentCompleter -CommandName Get-PowerBIWorkspace -ParameterName ID -ScriptBlock { | |
Get-PowerBIWorkspace | ForEach-Object { | |
$CompletionText = $_.Id | |
New-Object System.Management.Automation.CompletionResult ( | |
$CompletionText, | |
$_.Name, | |
'ParameterValue', | |
"$_ (PowerBIWorkspaceID)" | |
) | |
} | |
}; | |
<# When the Report Parameter is called -Name we do this #> | |
Register-ArgumentCompleter -CommandName Get-PowerBIReport -ParameterName Name -ScriptBlock { | |
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) | |
#$global:__LastFakeBoundParameter = $fakeBoundParameter | |
if ($fakeBoundParameter.ContainsKey('WorkspaceId')) { | |
(Get-PowerBIReport -WorkspaceId $fakeBoundParameter.WorkspaceId).Name | ForEach-Object { | |
New-Object System.Management.Automation.CompletionResult ( | |
"'$($_)'", | |
$_, | |
'ParameterValue', | |
"$_ (PBIReport)" | |
) | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment