How to get the computers domain name in matlab? - matlab

I tried getting domain name in c# as below,
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
Console.WriteLine("Domain name: {0}", properties.DomainName);
I have searched similar kind of approach in matlab for finding domain name. But I am not successful. Could anyone help me out like how we can get the domain name matlab(The domain name looks like yyy.xxxxx.com).
I got to know how to get computer name as below:
cc=getenv('computername');

How about this:
[s,cout] = system('net config workstation | findstr /C:"Full Computer name"');
FQDN= strtrim(strrep(cout,'Full Computer name',''))
FQDN=
XXXX.YYYY.com
This returns the fully qualified domain name (FQDN) of the computer . Where XXXX is your PC Name and YYYY is the domain.
Similarly if you just want the domain name:
[s,cout] = system('systeminfo | findstr /C:"Domain:"');
Domain = strtrim(strrep(cout,'Domain:',''))
Domain =
YYYY.com
EDIT: You can also get the FQDN using java in matlab like this:
FQDN = java.net.InetAddress.getLocalHost.getCanonicalHostName
FQDN =
XXXX.YYYY.com

You can read from the environment variable:
getenv('USERDOMAIN')

Related

Assign ITGlue Contact to the Field using API powershell

I just want to assign the contacts to Application's field and another field with API Powershell but I don't know how to do it. could anyone help me?
According to their API documentation, there is no 'Application' resource type. Is it a custom resource, or a field on a different type of object? (what type?)
Try installing ITGlue's PowerShell wrapper module ITGlueAPI from the gallery (or github link):
Install-Module ITGlueAPI
Import-Module ITGlueAPI
# Check out all the available commands
Get-Command -Module ITGlueAPI
# initial setup:
Add-ITGlueBaseURI -base_uri 'http://myapi.gateway.example.com'
Add-ITGlueAPIKey -ApiKey 'your-key-here'
# Play around with these kinds of "Get-" commands which exist for each resource type:
# This is a good way to see how the data is formatted, and which fields exist per resource
Get-ITGlueFlexibleAssets
Get-ITGlueContacts -organization_id 1234 -filter_first_name 'Foo' -sort 'first_name'
# To make changes, run similar "Set-" or "New-" commands with the updates in hash table format:
Set-ITGlueContacts -id 1234 -data #{
location-id = 795
location-name = "San Francisco - HQ"
field-name = "Value"
}

vsphere API - searchManagedEntity function always returns null

The searchManagedEntity function always returns null, I've tried many solutions on the web but unfortunately none of them worked.
Here's a snippet of my code:
ServiceInstance serviceInstance = authentification.connexionExsi();
Folder rootFolder = serviceInstance.getRootFolder();
System.out.println("Host" + (HostSystem) new InventoryNavigator(rootFolder).searchManagedEntity("HostSystem","192.168.1.44"));
Thank you in advance for your help <3
i've finally found the solution to this problem, you must use the name of ESXI host instead of the IP (ESXI Name = ESXI Hostname + Domain Name):
code:
ServiceInstance serviceInstance = authentification.connexionExsi();
Folder rootFolder = serviceInstance.getRootFolder();
System.out.println("Host"+new InventoryNavigator(rootFolder).searchManagedEntity("HostSystem","rabatos.Home").getName());
you can find the host & domain name in Dns & Routing, as depicted in the picture below:
Esxi Name

PowerCLI New-CDDrive - invalid datastore path

I'm trying to mount an iso from a datastore using VMWare PowerCLI. Code example:
$IsoPath = "vmstores:\1.2.2.1900443\datacenter1\datastore1\files.iso"
$cd = New-CDDrive -VM Vm001 -ISOPath $IsoPath
This fails with the error: New-CDDrive The operation for the entity "Vm001" failed with the following message: "Invalid datastore path 'vmstores:\1.2.2.1900443\datacenter1\datastore1\files.iso'
The path is valid. I confirm with:
Get-ChildItem "vmstores:\1.2.2.1900443\datacenter1\datastore1\files.iso"
Output:
Name Type Id
---- ---- --
Files.iso DatastoreFile
What is wrong with the command?
I guess that the vmstores: drive is a PowerShell Provider available on your local system, but the VHost has no idea about it, and the path needs to be in the form it understands, e.g. '[DatastoreName] folder\folder2\file.iso'.

How to Update DNS Records Programatically

I am trying to update a DNS Record which is at (I believe) the following path on the server:
ServerName -> Forward Lookup Zones -> domain.com -> test
Where the DNS record is called test, and is of type Host(A).
I downloaded the DNSShell module from here and tried changing the 'Data' column of the DNS record (which contains an IP address) with this command:
Set-DNSRecord -Identity "test.domain.com"
But I got this error:
Cannot validate argument on parameter 'Identity'. The argument "test.domain.com" does not match the "^\\.\root\MicrosoftDNS:MicrosoftDNS_" pattern. Supply an argument that matches "^\\.\root\MicrosoftDNS:MicrosoftDNS_" and try the command again.
So I updated the Identity parameter as follows:
Set-DNSRecord -Identity "\\Servername\root\MicrosoftDNS:MicrosoftDNS_"
But now I am seeing:
Set-DNSRecord : Specified argument was out of the range of the valid values. Parameter name: Path
When I try adding a -Path, it says there is not such parameter! Does anyone know where I need to add the test.domain.com part of the DNS to tell the command which record to update? The documentation on this module is incomplete for this part of it and I can't seem to find any alternatives.
I can call Get-DNSRecord and see the record I need to update, but any attempts to Set are blocked because I have no idea how these paths are built.
Any help is much appreciated.
You can use also default PowerShell module for DNS server from Microsoft, example would then look something like this:
Add-DnsServerResourceRecordA -Name "recordname" -IPv4Address "192.168.0.0" -ZoneName "domain.com" -AllowUpdateAny -AgeRecord
In case you need removal before that something like this should work:
Remove-DnsServerResourceRecord -ZoneName "domain.com" -Name "recordname" -RRType "A" -Force
I managed to overcome this by using ye olde classic CMD command:
dnscmd /RecordAdd domain.com recordname RecordType /Aging /OpenAcl A 192.168.0.0
This adds a new record, and seems to do so even when another record with the same name (but different IP) exists.
So in my case, I will have to use dnscmd to first remove the existing record before adding a new one (as I actually just want to update the IP address of the existing record).
Command for removing dns record :
dnscmd /recorddelete domain.com recordname
More details can be found here.

Modify datasource IP addresses in WebSphere Application Server

I have nearly a hundred data sources in a WebSphere Application Server (WAS) and due to office relocation, the IP of the database servers have changed and I need to update the datasource IP addresses in my WAS too.
Considering it error-prone to update hundred IPs through admin console.
Is there any way that I can make the change by updating config files or running a script? My version of WAS is 7.0.
You should be able to use the WAS Admin Console's built-in "command assistance" to capture simple code snippets for listing datasources and changing them by just completing those operations in the UI once.
Take those snippets and create a new jython script to list and update all of them.
More info on command assistance:
http://www.ibm.com/developerworks/websphere/library/techarticles/0812_rhodes/0812_rhodes.html
wsadmin scripting library:
https://github.com/wsadminlib/wsadminlib
You can achieve this using wsadmin scripting. Covener has the right idea with using the admin console's command assistance to do the update once manually (to get the code) and then dump that into a script that you can automate.
The basic idea is that a datasource has a set of properties nested under it, one of which is the ip address. So you want to write a script that will query for the datasource, find its nested property set, and iterate over the property set looking for the 'ipAddress' property to update.
Here is a function that will update the value of the "ipAddress" property.
import sys
def updateDataSourceIP(dsName, newIP):
ds = AdminConfig.getid('/Server:myServer/JDBCProvider:myProvider/DataSource:' + dsName + '/')
propertySet = AdminConfig.showAttribute(ds, 'propertySet')
propertyList = AdminConfig.list('J2EEResourceProperty', propertySet).splitlines()
for prop in propertyList:
print AdminConfig.showAttribute(prop, 'name')
if (AdminConfig.showAttribute(prop, 'name') == 'ipAddress'):
AdminConfig.modify(prop, '[[value '" + newIP + "']]')
AdminConfig.save();
# Call the function using command line args
updateDataSourceIP(sys.argv[0], sys.argv[1])
To run this script you would invoke the following from the command line:
$WAS_HOME/bin/wsadmin.sh -lang jython -f /path/to/script.py myDataSource 127.0.0.1
**Disclaimer: untested script. I don't know the name of the "ipAddress" property off the top of my head, but if you run this once it will print out all the properties on your ds, so you can get it there
Some useful links:
Basics about jython scripting
Modifying config objects using wsadmin
As an improvement to aguibert's script, to avoid having to provide all 100 datasource names and to update it to correct the containment path of the configuration id, consider this script which will update all datasources, regardless of the scope at which they're defined. As always, backup your configuration before beginning and once you're satisified the script is working as expected, replace the AdminConfig.reset() with save(). Note, these scripts will likely not work properly if you're using connection URLs in your configuration.
import sys
def updateDataSourceIP(newIP):
datasources = AdminConfig.getid('/DataSource:/').splitlines()
for datasource in datasources:
propertySet = AdminConfig.showAttribute(datasource, 'propertySet')
propertyList = AdminConfig.list('J2EEResourceProperty', propertySet).splitlines()
for prop in propertyList:
if (AdminConfig.showAttribute(prop, 'name') == 'serverName'):
oldip = AdminConfig.showAttribute(prop, 'value')
print "Updating serverName attribute of datasource '" + datasource + "' from " + oldip + " to " + sys.argv[0]
AdminConfig.modify(prop, '[[value ' + newIP + ']]')
AdminConfig.reset();
# Call the function using command line arg
updateDataSourceIP(sys.argv[0])
The script should be invoked similarly to the above, but without the datasource parameter, the only parameter is the new hostname or ip address:
$WAS_HOME/bin/wsadmin.sh -lang jython -f /path/to/script.py 127.0.0.1