PSDefaultParameterValues and import-module

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of David Zemdegs David Zemdegs 4 months, 3 weeks ago.

  • Author
    Posts
  • #65523
    Profile photo of David Zemdegs
    David Zemdegs
    Participant

    Greetings,
    Users running a utility I wrote have RSAT installed on their Windows 7 machines.
    This was to access Windows 2003 domain controllers.
    We are finally upgrading to Server 2012 R2 DCs and I wanted my utility to have access to all the new cmdlets.
    So I tried putting this in my code:

    		$Global:ActiveSiteDC = (Get-ADDomainController -Discover -MinimumDirectoryServiceVersion Windows2008).name
    		$s2012 = New-PSSession -ComputerName $Global:ActiveSiteDC -ea stop
    		Import-Module ActiveDirectory -PSSession $s2012 -force -Verbose:$false -ea stop
    

    I have found since I have done this that the import-module fails about 10% of the time for an unknown reason.
    The other problem is that I had been using PSDefaultParameterValues to set some defaults for all AD cmdlets. I understand this does not work when importing modules remotely.
    So my questions are:
    How can I give my users full access to all Server 2012 cmdlets and also apply default parameter values to them please?
    Thanks
    David Z

  • #65605
    Profile photo of Don Jones
    Don Jones
    Keymaster

    It's a little hard to tell you why it fails 10% of the time with the information you've provided; you'd need to troubleshoot that by looking through (for example) the Remoting logs on both machines.

    The default parameter thing is what it is. It doesn't work for imported commands.

    Alternately, you can just have people use Enter-PSSession to remote into the DC, and then run the commands "there" rather than trying to run them via implicit remoting. Or, and this would be the best, use the JEA toolkit to set up a Remoting endpoint that contains the commands you want. You could have that endpoint run a startup script that applies your default values. That would all exist remotely and you'd use Enter-PSSession to access the toolkit.

    • #65664
      Profile photo of David Zemdegs
      David Zemdegs
      Participant

      Thanks.
      It's a Powershell studio application (exe).
      I could use the JEA toolkit but the number of commands is quite large and I am adding new ones regularly so that would be too hard to maintain.
      Enter-PSSession is too complicated for the help desk people.
      At this stage I've decided to use Invoke-command pointing to a DC when I need to use a cmdlet that RSAT doesnt have.
      Cheers
      David Z

You must be logged in to reply to this topic.