Cyber_Profile.psm1
# Prepare Cyber Module lists. Set-Variable -Option "Constant" -Name "CYBER_MODULE_LIST" -Value ( "Hyper-V.Tools", "DockerCompletion", "NtObjectManager", "posh-git" ) Set-Variable -Option "Constant" -Name "CYBER_MODULES_PRESENT" -Value ( Get-Module -ListAvailable -Name $CYBER_MODULE_LIST | Select-Object -ExpandProperty "Name" -Unique ) Set-Variable -Option "Constant" -Name "CYBER_MODULES_MISSING" -Value ( $CYBER_MODULE_LIST | Where-Object -FilterScript { $_ -notin $CYBER_MODULES_PRESENT } ) # Import modules. if ($null -ne $CYBER_MODULES_PRESENT) { $CYBER_MODULES_PRESENT | Import-Module -Global } # Notify about missing cyber modules, if there are any. if ($null -ne $CYBER_MODULES_MISSING) { Write-Warning -Message "The following cyber modules are missing: $CYBER_MODULES_MISSING.`nYou can install them using the Install-CyberModules cmdlet." } # PowerShell settings $PSDefaultParameterValues = @{ "Format-Table:AutoSize" = $true } # PSReadLine settings Set-PSReadLineOption -PredictionViewStyle ListView # posh-git settings if ($null -ne (Get-Module -Name "posh-git")) { $GitPromptSettings.DefaultPromptBeforeSuffix.Text = "`n" $GitPromptSettings.BeforePath.Text ="[" $GitPromptSettings.AfterPath.Text ="]" } # Cmdlets function New-PSCredential { [Diagnostics.CodeAnalysis.SuppressMessage("PSAvoidUsingPlainTextForPassword", "", Justification="By design")] [CmdletBinding()] param ( [Parameter(Mandatory=$true)][string]$Username, [Parameter(Mandatory=$true)][string]$Password ) $password_encrypted = ConvertTo-SecureString -String $password -AsPlainText -Force $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password_encrypted return $credential } function Install-CyberModules { Install-Module -Name $CYBER_MODULES_MISSING -Force -AllowClobber } # dotnet.exe argument completer $dotnet_argument_completer = { param($wordToComplete, $commandAst, $cursorPosition) dotnet complete --position $cursorPosition $commandAst.ToString() | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, "ParameterValue", $_) } } Register-ArgumentCompleter -Native -CommandName "dotnet" -ScriptBlock $dotnet_argument_completer Update-FormatData -PrependPath "$PSSCriptRoot\System.IO.FileInfo.Format.ps1xml" |