Created
August 11, 2016 19:24
-
-
Save mrkwbr/319c4552e623783fe308b1eb1493d1b7 to your computer and use it in GitHub Desktop.
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
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