Jump to content

LDAP Import and Asset Import tools that do not required a source connection?


samwoo

Recommended Posts

Hello,

I am looking to integrate as part of the new Starter Process to allow users to run a Powershell script with the Active Directory module to create / copy new users in Active Directory, which within the process will also run LDAP_Import. I've seen a post on the forum where we can populate the conf file based on what's returned from the Active Directory Module.

I would like to be able to do the same thing with Asset_Import using the Configuration Manager module in Powershell.

The problem is that both tools require a connection to either Active Directory or SCCM, when I was just hoping to be able to connect to the Hornbill instance and use Powershell to populate the .conf which will then run the relevant tool.

Is it possible to have a "Light" variant of these tools, which doesn't require a connection to either Active Directory or SCCM? (As I will be using Powershell for this purpose)

Thanks,

Samuel

ps. I cannot create a poll for some reason

Link to comment
Share on other sites

27 minutes ago, TrevorKillick said:

@samwoo

Sorry little confused by your request without a connection to SCCM or AD how where would the source of the Asset Data come from when the Asset Import is run? 

Kind Regards

Trevor Killick

Hi @Trevor Killick,

Powershell will pull this information using the Configuration Manager module, then populate the fields in the .conf file which the tool would import / update into Hornbill.

Our infrastructure are investigating running this tool to update Hornbill daily, but there is a use where via the Powershell Script, a New Starter is created, uploaded into Hornbill straight away - if there is any assets we can give them at that point in time we can automatically update the existing asset in Hornbill to hold the value of the new owner.

I was only thinking of these tools being used for a single use, whilst keeping the overnight ones running as we do already.

Sorry if i'm not making any sense, very hot :(

Thanks,

Samuel

edit: To clarify that the user will type the asset number into the Powershell prompt, the Configuration Manager module will allow me to do checks to ensure that it's a valid Asset etc. Before populating the .conf file with the name and any other details.

edit 2: The powershell modules will automagically connect to the Active Directory or Asset database. I have already used Powershell to auto-create the Exchange mailbox for a new starter, but prior to this the user still has to be entered directly into AD. So i thought (in this case) why not include the whole process of creating the user in AD, creating the mailbox, upload the user into Hornbill, and assign any assets if available. All in a single process.

 

Link to comment
Share on other sites

4 minutes ago, TrevorKillick said:

@samwoo

Ok so effectively you want to create a new user or asset from the output of PowerShell something like a CSV import.

Kind Regards

Trevor Killick

Hi Trevor,

That is one way it could be used to populate the .conf file after looping through a CSV file and running the import tool each time, so in a way yes that is correct. New Starters will always be allocated existing assets so the process would need to update the Hornbill Asset rather than create a new one.

I did try connecting to Hornbill's RESTFUL API using Powershell, but had no luck (i might have been doing it wrong) - our Integrations Officer is currently busy on other projects so hence the reason for this request to see if there could be another solution.

Thanks,

Samuel

Link to comment
Share on other sites

  • 1 month later...

Hi @samwoo,

Just to let you know, I released a Hornbill API Powershell module to our public Github yesterday, which should help in allowing you to fire Hornbill API calls from your Powershell scripts. The repository for the module is here:

https://github.com/hornbill/powershellHornbillAPIModule

I've included a couple of usage examples - one for returning asset records, and one for returning an asset type then inserting a new asset record. The module functions are documented within the source code, but please let me know if you need any further information.

Hope this helps!

Steve

  • Thanks 1
Link to comment
Share on other sites

27 minutes ago, Steve G said:

Hi @samwoo,

Just to let you know, I released a Hornbill API Powershell module to our public Github yesterday, which should help in allowing you to fire Hornbill API calls from your Powershell scripts. The repository for the module is here:

https://github.com/hornbill/powershellHornbillAPIModule

I've included a couple of usage examples - one for returning asset records, and one for returning an asset type then inserting a new asset record. The module functions are documented within the source code, but please let me know if you need any further information.

Hope this helps!

Steve

Hi @Steve G,

This is awesome! I will certainly be having a look at this :D  +1

Many thanks,

Samuel

  • Like 1
Link to comment
Share on other sites

Hi @samwoo,

You probably just need to set the HTTP_PROXY or HTTPS_PROXY environment variables in your operating system. If you're running Windows, they can be set from the command line using the following: 

set HTTP_PROXY=HOST:PORT

set HTTPS_PROXY=HOST:PORT  

Where "HOST" is the IP address or host name of your Proxy Server and "PORT" is the specific port number.

Kind regards,

Steve

Link to comment
Share on other sites

44 minutes ago, Steve G said:

Hi @samwoo,

You probably just need to set the HTTP_PROXY or HTTPS_PROXY environment variables in your operating system. If you're running Windows, they can be set from the command line using the following: 

set HTTP_PROXY=HOST:PORT

set HTTPS_PROXY=HOST:PORT  

Where "HOST" is the IP address or host name of your Proxy Server and "PORT" is the specific port number.

Kind regards,

Steve

Hi @Steve G,

Thanks for this - I had already done the above when I was looking into Power BI a few weeks ago. It hasn't helped with the xmlmc module :(

This is the message I received when I run the module:

Quote

# Important! Remove XMLMC module from memory for security once XMLMC calls complete
Remove-Module xmlmcModule
API Call Status : fail
Error Returned  : System.Net.WebException: The remote server returned an error: (407) Proxy Authe
ntication Required.
   at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
   at System.Net.HttpWebRequest.GetRequestStream()
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.SetRequestContent(WebRequest request, XmlN
ode xmlNode)
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
 

We are using single sign-on, also I am using an API key set against the very first user that was created when Hornbill was set up, not an API key set against my username in Hornbill - could this be the reason?

Thanks,

Samuel

Link to comment
Share on other sites

Hi @samwoo,

Ah, I see. This is not a response from Hornbill, it's from your proxy. You'll need to add the -Proxy and either one of the -ProxyCredential / -ProxyUseDefaultCredentials parameters to the Invoke-WebRequest command in the module code, as per the MS documentation:

https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/invoke-webrequest

So row 276 in the module source is currently:

$r = Invoke-WebRequest -Uri $script:URI -Method Post -Headers $script:headers -ContentType "text/xmlmc" -Body $script:body -ErrorAction:Stop

Add the following to the end of that row:

-Proxy "yourproxyaddress" -ProxyUseDefaultCredentials

This should route the request through your proxy, using your logged on credentials as its authentication method.

If you could let me know how you get on, and if this works then I'll add some additional code in the module to cater for proxy authentication.

Cheers,

Steve

  • Thanks 1
Link to comment
Share on other sites

26 minutes ago, Steve G said:

Hi @samwoo,

Ah, I see. This is not a response from Hornbill, it's from your proxy. You'll need to add the -Proxy and either one of the -ProxyCredential / -ProxyUseDefaultCredentials parameters to the Invoke-WebRequest command in the module code, as per the MS documentation:

https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/invoke-webrequest

So row 276 in the module source is currently:


$r = Invoke-WebRequest -Uri $script:URI -Method Post -Headers $script:headers -ContentType "text/xmlmc" -Body $script:body -ErrorAction:Stop

Add the following to the end of that row:


-Proxy "yourproxyaddress" -ProxyUseDefaultCredentials

This should route the request through your proxy, using your logged on credentials as its authentication method.

If you could let me know how you get on, and if this works then I'll add some additional code in the module to cater for proxy authentication.

Cheers,

Steve

Hi @Steve G,

Fantastic! This has worked! 

Many thanks for the assist - I am now able to use the xmlmc module in Powershell.

I will update the module once you have added the extra functionality.

Cheers,

Samuel

  • Like 1
Link to comment
Share on other sites

Hi @samwoo,

I've added support for proxy authentication to the module, and the code is up on Github now.

There's a new function that has been made available: Set-Proxy. It's documented within the source code, but you can use this in a couple of ways:

If you want to use the current Windows user credentials to authenticate against the proxy, then you just need to add the following to your code at any point before you run Invoke-XMLMC:

Set-Proxy "http://yourproxyaddress:andportifapplicable"

The Set-Proxy function supports an additional input parameter, so that you can define proxy credentials to authenticate with. This additional parameter can either be just a username in a string (and the script will then ask for the password at this point), or a PSCredential object, such as one created by the Get-Credential cmdlet. So to supply a username and have the script prompt for the password, add the following to your code before the Invoke-XMLMC:

$User = "Domain01\User01"
Set-Proxy "http://yourproxyaddress:andportifapplicable" $User

And if you want to supply a full PSCredential object:

$User = "Domain01\User01"
$PWord = ConvertTo-SecureString -String "password" -AsPlainText -Force
$CredObject = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PWord
Set-Proxy "http://yourproxyaddress:andportifapplicable" $CredObject

Although, it's probably easier if the account you run this with can just authenticate against your proxy server, and not provide authentication details as a parameter to Set-Proxy, as you shouldn't really be saving plain-text passwords in your Powershell scripts ;)

Let me know how you get on :)

Cheers,

Steve

Link to comment
Share on other sites

  • Victor changed the title to LDAP Import and Asset Import tools that do not required a source connection?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...