Goal:
I am attempting to create a script that would automatically establish a PSSession to a Windows server for implicit remoting.
Problem:
Export-PSSession : Proxy creation has been skipped for the '%' command, because Windows PowerShell could not verify the safety of the command name.
At Z:Somewhere\aScript.ps1:12 char:3
+ Export-PSSession -Session $ServerPS -OutputModule 'First Module' - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Export-PSSession], InvalidOperationException
+ FullyQualifiedErrorId : ErrorSkippedUnsafeCommandName,Microsoft.PowerShell.Commands.ExportPSSessionCommand
Side notes:
A large number of users will use this script to establish PSSessions daily, I am trying to find the most efficient way to get all the users to access these modules - Amodule, Bmodule and Cmodule. Additionally, the script still works despite the above mentioned error.
Here is a sample of my script:
$Server = New-PSSession -ComputerName ServerPS -Authentication Kerberos
Set-Alias -Name go -Value Get-CustomMods -Description 'Gets the modules'
function Get-CustomMods
{
# Import first module
Write-Verbose -Message 'Importing First module'
Invoke-command { import-module 'Amodule.ps1' } -session $ServerPS
Export-PSSession -Session $Server -OutputModule 'Amodule' -Force -AllowClobber
# Import second module
Write-Verbose -Message 'Importing Second Module'
Invoke-command { import-module 'Bmodule.ps1'} -session $ServerPS
Export-PSSession -Session $Server -OutputModule 'Bmodule' -Force -AllowClobber
# Import third module
Write-Verbose -Message 'Importing Third Module'
Invoke-command { import-module 'Cmodule.ps1' } -session $ServerPS
Export-PSSession -Session $Server -OutputModule 'Cmodule' -Force -AllowClobber
}
Question:
Is there a more effective way to structure/write this script given my goal and problem?