Skip to content

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentDardenne committed Mar 18, 2018
1 parent f1e3d17 commit 82206ac
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 0 deletions.
Binary file added Runspace contraint/RunspaceContraint.pdf
Binary file not shown.
34 changes: 34 additions & 0 deletions Runspace contraint/Source/DataSection.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
$File='C:\Temp\DataSection1.ps1'
@'
Data {
if ($PSCulture -eq 'Fr-fr')
{"Français"}
else
{"Autre"}
}
'@ > $File

. $File

$File='C:\Temp\DataSection2.ps1'
@'
Data {
if ($PSVersionTable.PSVersion -eq ([version]"2.0.0.0"))
{"PowerShell 2.0"}
else
{"PowerShell >= 3.0 "}
}
'@ > $File

. $File

$File='C:\Temp\DataSection4.ps1'
@'
Function Get-RSInfo {$ExecutionContext.host.Runspace|Select-Object * }
Data -supportedCommand Get-RSInfo {
Get-RSInfo
}
'@ > $File

. $File
31 changes: 31 additions & 0 deletions Runspace contraint/Source/RS1-1.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$InitialSessionState= [System.Management.Automation.Runspaces.InitialSessionState]::Create()

$SessionStateCmdletEntry = New-Object System.Management.Automation.Runspaces.SessionStateCmdletEntry 'Get-ChildItem','Microsoft.PowerShell.Commands.GetChildItemCommand',$null
$InitialSessionState.Commands.Add($SessionStateCmdletEntry)

$Provider = New-Object System.Management.Automation.Runspaces.SessionStateProviderEntry 'FileSystem',([Microsoft.PowerShell.Commands.FileSystemProvider]),$null
$InitialSessionState.Providers.Add($Provider)

try {
$Runspace= [RunspaceFactory]::CreateRunspace($InitialSessionState)
$Runspace.Open()
try {
$PS = [PowerShell]::Create()
$PS.Runspace = $Runspace
$null=$PS.AddCommand("Get-ChildItem").AddParameter('Path','C:\temp\')

$Results = $PS.Invoke()
if ($PS.Streams.Error.Count -gt 0)
{
Write-Warning "Erreur"
$PS.Streams.Error
}
}
finally {
$PS.Dispose()
}
}
finally {
$Runspace.Dispose()
}

30 changes: 30 additions & 0 deletions Runspace contraint/Source/RS1-2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
$InitialSessionState= [System.Management.Automation.Runspaces.InitialSessionState]::Create()

$SessionStateCmdletEntry = New-Object System.Management.Automation.Runspaces.SessionStateCmdletEntry 'Get-ChildItem','Microsoft.PowerShell.Commands.GetChildItemCommand',$null
$InitialSessionState.Commands.Add($SessionStateCmdletEntry)

$Provider = New-Object System.Management.Automation.Runspaces.SessionStateProviderEntry 'FileSystem',([Microsoft.PowerShell.Commands.FileSystemProvider]),$null
$InitialSessionState.Providers.Add($Provider)

try {
$Runspace= [RunspaceFactory]::CreateRunspace($InitialSessionState)
$Runspace.Open()
try {
$PS = [PowerShell]::Create()
$PS.Runspace = $Runspace
$PS.AddCommand("Get-Process") > $null

$Results = $PS.Invoke()
if ($PS.Streams.Error.Count -gt 0)
{
Write-Warning "Erreur"
$PS.Streams.Error
}
}
finally {
$PS.Dispose()
}
}
finally {
$Runspace.Dispose()
}
28 changes: 28 additions & 0 deletions Runspace contraint/Source/RS1.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$InitialSessionState= [System.Management.Automation.Runspaces.InitialSessionState]::Create()

$SessionStateCmdletEntry = New-Object System.Management.Automation.Runspaces.SessionStateCmdletEntry 'Get-ChildItem','Microsoft.PowerShell.Commands.GetChildItemCommand',$null
$InitialSessionState.Commands.Add($SessionStateCmdletEntry)

try {
$Runspace= [RunspaceFactory]::CreateRunspace($InitialSessionState)
$Runspace.Open()
try {
$PS = [PowerShell]::Create()
$PS.Runspace = $Runspace
$null=$PS.AddCommand("Get-ChildItem").AddParameter('Path','C:\temp\')

$Results = $PS.Invoke()
if ($PS.Streams.Error.Count -gt 0)
{
Write-Warning "Erreur"
$PS.Streams.Error
}
}
finally {
$PS.Dispose()
}
}
finally {
$Runspace.Dispose()
}

33 changes: 33 additions & 0 deletions Runspace contraint/Source/RS2-1.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
$InitialSessionState= [System.Management.Automation.Runspaces.InitialSessionState]::Create()

$SessionStateCmdletEntry = New-Object System.Management.Automation.Runspaces.SessionStateCmdletEntry 'Get-ChildItem','Microsoft.PowerShell.Commands.GetChildItemCommand',$null
$InitialSessionState.Commands.Add($SessionStateCmdletEntry)

$Provider = New-Object System.Management.Automation.Runspaces.SessionStateProviderEntry 'FileSystem',([Microsoft.PowerShell.Commands.FileSystemProvider]),$null
$InitialSessionState.Providers.Add($Provider)
$InitialSessionState.LanguageMode=[System.Management.Automation.PSLanguageMode]::RestrictedLanguage

try {
$Runspace= [RunspaceFactory]::CreateRunspace($InitialSessionState)
$Runspace.Open()
try {
$PS = [PowerShell]::Create()
$PS.Runspace = $Runspace
$PS.AddScript("Get-ChildItem -Path 'c:\temp'") > $null

$Results = $PS.Invoke()
if ($PS.Streams.Error.Count -gt 0)
{
Write-Warning "Erreur"
$PS.Streams.Error
}
}
finally {
$PS.Dispose()
}
}
finally {
$Runspace.Dispose()
}


31 changes: 31 additions & 0 deletions Runspace contraint/Source/RS2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$InitialSessionState= [System.Management.Automation.Runspaces.InitialSessionState]::Create()

$SessionStateCmdletEntry = New-Object System.Management.Automation.Runspaces.SessionStateCmdletEntry 'Get-ChildItem','Microsoft.PowerShell.Commands.GetChildItemCommand',$null
$InitialSessionState.Commands.Add($SessionStateCmdletEntry)

$Provider = New-Object System.Management.Automation.Runspaces.SessionStateProviderEntry 'FileSystem',([Microsoft.PowerShell.Commands.FileSystemProvider]),$null
$InitialSessionState.Providers.Add($Provider)

try {
$Runspace= [RunspaceFactory]::CreateRunspace($InitialSessionState)
$Runspace.Open()
try {
$PS = [PowerShell]::Create()
$PS.Runspace = $Runspace
$null=$PS.AddScript("Get-ChildItem -Path 'C:\Temp'")

$Results = $PS.Invoke()
if ($PS.Streams.Error.Count -gt 0)
{
Write-Warning "Erreur"
$PS.Streams.Error
}
}
finally {
$PS.Dispose()
}
}
finally {
$Runspace.Dispose()
}

0 comments on commit 82206ac

Please sign in to comment.