Skip to content

Instantly share code, notes, and snippets.

@mrkwbr
Created August 11, 2016 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkwbr/319c4552e623783fe308b1eb1493d1b7 to your computer and use it in GitHub Desktop.
Save mrkwbr/319c4552e623783fe308b1eb1493d1b7 to your computer and use it in GitHub Desktop.
import-module DFSN
[string[]]$PublicCmdlets = 'Clear-Host','Get-Alias','Get-DFSNFolder','New-DFSNFolder'
[string[]]$PublicAliases = 'exsn','cls','gal'
[string[]]$PublicScripts = $Null
[string[]]$Apps = 'whoami'
[string[]]$PublicApps = ForEach ($app in $apps) {
Get-Command $app | Select -ExpandProperty Definition
}
foreach ($cmd in (Get-Command).where{$PublicCmdlets -notcontains $_.Name}) {
$cmd.Visibility = "private"
}
foreach ($var in Get-Variable) {
$var.Visibility = "private"
}
$ExecutionContext.SessionState.Applications.Clear()
$ExecutionContext.SessionState.Scripts.Clear()
$ExecutionContext.SessionState.LanguageMode = "NoLanguage"
If ($PublicApps) {
$ExecutionContext.SessionState.Applications.AddRange(($PublicApps -as [System.Collections.Generic.IEnumerable[string]]))
}
If ($PublicScripts) {
$ExecutionContext.SessionState.Scripts.AddRange(($PublicScripts -as [System.Collections.Generic.IEnumerable[string]]))
}
$iss = [Management.Automation.Runspaces.InitialSessionState]::CreateRestricted("remoteserver")
foreach ($proxy in $iss.Commands | where { $_.Visibility -eq "Public"}) {
$cmd = Get-Command -type cmdlet -ea silentlycontinue $proxy.name
if ($cmd) {
$a = Set-Alias "$($proxy.name)" "$($cmd.ModuleName)\$($cmd.Name)" -PassThru
$a.Visibility = "Private"
}
Set-Item "function:global:$($proxy.Name)" $proxy.Definition
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment