Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The basic commands I always put in all of my PowerShell $Profile.CurrentUserAllHosts
Import-Module SqlServer;
cd $home\Documents\PoSh\Load\
. .\Get-History2.ps1;
cd C:\temp;
<# First we need an argument completer for -ServerInstance #>
Register-ArgumentCompleter -ParameterName ServerInstance -ScriptBlock {
(dir -Recurse SQLSERVER:\SQLRegistration\'Database Engine Server Group'\ |
?{ $_.Mode -ne 'd'} |
Group-Object ServerName).Name | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (SQLInstance)"
)
}
};
<# When the Database Parameter is called -Name we do this #>
Register-ArgumentCompleter -ParameterName Name -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
#$global:__LastFakeBoundParameter = $fakeBoundParameter
if ($fakeBoundParameter.ContainsKey('ServerInstance')) {
(dir "SQLSERVER:\SQL\$($fakeBoundParameter.ServerInstance)\Databases").Name | ForEach-Object {
New-Object System.Management.Automation.CompletionResult (
$_,
$_,
'ParameterValue',
"$_ (Database)"
)
}
}
};
<# When the Parameter is called -Database we do this to provide choices #>
Register-ArgumentCompleter -ParameterName Database -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
if ($fakeBoundParameter.ContainsKey('ServerInstance')) {
(Get-SqlDatabase -ServerInstance $($fakeBoundParameter.ServerInstance)).Name | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (Database)"
)
}
}
};
<# When the Parameter is called -Database we do this #>
Register-ArgumentCompleter -ParameterName DatabaseName -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
if ($fakeBoundParameter.ContainsKey('ServerInstance')) {
(Get-SqlDatabase -ServerInstance $($fakeBoundParameter.ServerInstance)).Name | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (Database)"
)
}
}
};
<# We need an argument completer for -Workspace #>
Register-ArgumentCompleter -ParameterName Workspace -ScriptBlock {
(Get-PowerBIWorkspace).Name | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (PowerBIWorkspace)"
)
}
};
<# We need an argument completer for -WorkspaceID #>
Register-ArgumentCompleter -ParameterName WorkspaceID -ScriptBlock {
(Get-PowerBIWorkspace).Id | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (PowerBIWorkspaceID)"
)
}
};
<# When the Report Parameter is called -Name we do this #>
Register-ArgumentCompleter -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',
"$_ (Database)"
)
}
}
};
<# First we need an argument completer for -SourceWorkspaceName #>
Register-ArgumentCompleter -ParameterName SourceWorkspaceName -ScriptBlock {
(Get-PowerBIWorkspace).Name | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (SQLInstance)"
)
}
};
<# First we need an argument completer for -TargetWorkspaceName #>
Register-ArgumentCompleter -ParameterName TargetWorkspaceName -ScriptBlock {
(Get-PowerBIWorkspace).Name | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (SQLInstance)"
)
}
};
Start-Transcript -OutputDirectory "$($HOME)\Documents\Transcripts";
Import-Module SqlServer;
cd C:\temp;
<# First we need an argument completer for -ServerInstance #>
Register-ArgumentCompleter -ParameterName ServerInstance -ScriptBlock {
(dir -Recurse SQLSERVER:\SQLRegistration\'Database Engine Server Group'\ |
?{ $_.Mode -ne 'd'} |
Group-Object ServerName).Name | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (SQLInstance)"
)
}
};
<# When the Database Parameter is called -Name we do this #>
Register-ArgumentCompleter -ParameterName Name -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
#$global:__LastFakeBoundParameter = $fakeBoundParameter
if ($fakeBoundParameter.ContainsKey('ServerInstance')) {
(dir "SQLSERVER:\SQL\$($fakeBoundParameter.ServerInstance)\Databases").Name | ForEach-Object {
New-Object System.Management.Automation.CompletionResult (
$_,
$_,
'ParameterValue',
"$_ (Database)"
)
}
}
};
<# When the Parameter is called -Database we do this to provide choices #>
Register-ArgumentCompleter -ParameterName Database -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
if ($fakeBoundParameter.ContainsKey('ServerInstance')) {
(Get-SqlDatabase -ServerInstance $($fakeBoundParameter.ServerInstance)).Name | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (Database)"
)
}
}
};
<# When the Parameter is called -Database we do this #>
Register-ArgumentCompleter -ParameterName DatabaseName -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
if ($fakeBoundParameter.ContainsKey('ServerInstance')) {
(Get-SqlDatabase -ServerInstance $($fakeBoundParameter.ServerInstance)).Name | ForEach-Object {
$CompletionText = $_
New-Object System.Management.Automation.CompletionResult (
$CompletionText,
$_,
'ParameterValue',
"$_ (Database)"
)
}
}
};
Start-Transcript -OutputDirectory "$($HOME)\Documents\Transcripts";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.