Quantcast
Viewing all articles
Browse latest Browse all 21975

create connect-server type powershell cmdlet

We use a product called papercut to handle printing for students and staff, and i'm wanting to create a powershell module that contains cmdlets that map to functions that are exposed by their Api. These cmdlets require a server connection in order to work, basically the object contains the name of the server to connect to, the port it's listening on, and an authentication token that is a string.

I'd like to have something like this

Connect-PcutServer -Server pcut -Port 9191 -authToken blahblahblah

once connected then subsequent cmdlets like add-printer, rename-user and so on would be able to take advantage of that connection. if were writing this in powershell instead of c# I would probably just store those as a $global:variable or something similar. Then the functions would check to see if $global:variable existed, if so it would do things, if not it would prompt the user to run the connect-server cmdlet.

I can create a cmdlet called connect-server, that accepts those three params, but is the proper way of doing something like this to return a $global:object (is that even possible), or is there a better way to handle this?

Thanks,


Jeffrey S. Patton Jeffrey S. Patton Systems Specialist, Enterprise Systems University of Kansas 1001 Sunnyside Ave. Lawrence, KS. 66045 (785) 864-0242 | http://patton-tech.com


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>