Using add-type and import-module you can dynamically compile and load an assembly without any intermediate assembly files to cleanup.
For instance, to run a cmdlet on a remote machine you could send over the cmdlet source code, compile, import, and run it all on the fly.
Let’s say you have your cmdlet called Use-MyCmdlet as C# code in the file mycode.cs:
PS> [string] $code = Get-Content mycode.csPS> $s = New-PSSession remoteHostPS> Invoke-Command $s ` {(Add-Type -TypeDefinition $args[0] -PassThru).assembly | Import-Module} ` -ArgumentList $codePS> Invoke-Command $s {Use-MyCmdlet}PS> Remove-PSSession $s
Nigel Sharples [MSFT]