How to get list of roles and members in an Azure Analysis service via Powershell - azure-analysis-services

We want to get the list of roles and members existing in an Azure Analysis services via Powershell.
Is it possible?
https://learn.microsoft.com/en-us/azure/analysis-services/analysis-services-powershell
Based on these list , I did not get any list to get these details

I have provided a solution over here. You basically need to call the tabular object model directly from PowerShell scripts. Please find below script which will give the roles and members of a Model.
[Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
$ServerName = "asazure://westus.asazure.windows.net/abc:rw"
$DB = "adventureworks"
$Server = New-Object Microsoft.AnalysisServices.Server
$Server.Connect($ServerName)
$Database = $Server.Databases.Item($DB)
foreach ( $roles in $Database.Model.Roles) {
#Write-Output $roles.Name
foreach ( $role in $roles) {
Write-Output $role.Name
Write-Output "----------------------"
foreach ( $member in $roles.Members) {
"Member Name: " + $member.Name
}
Write-Output "`n"
}
}
Output:

Related

Why does Graph API return a "not found" error when querying for user attributes?

I am relatively new to Microsoft Graph API. I am trying to extract a list of user profile information. When I run either of the following requests, I get a valid response:
Get displayname and birthday for single user:
GET https://graph.microsoft.com/v1.0/users/___userID___?$select=displayName,birthday
Get displayname for all users:
GET https://graph.microsoft.com/v1.0/users/?$select=displayName
However, when I try to run the following query, I receive an error:
Get displayname and birthday for all users:
GET https://graph.microsoft.com/v1.0/users/?$select=displayName,birthday
The error I receive is as follows:
{
"error": {
"code": "UnknownError",
"message": "",
"innerError": {
"date": "2023-02-02T05:57:08",
"request-id": "e8ae37af-3478-4446-a328-9d79f7aac0fc",
"client-request-id": "a667c3f1-0183-3382-c601-2197456a758d"
}
}
}
This error seems to occur with only some attribute types, forexample hiredate and birthday. If I query for displayname and userprincipalname, I do get the same error.
I would appreciate any suggestions.
For anyone reading this in the future, I was able to achieve my desired outcome using the following script.
Thanks to user2250152's answer, I realized I could not query for the necessary properties in bulk. So I used PowerShell to first pull a list of all users, and then loop through each of them to query the required properties.
# Report on User Profiles in SPO
# Define attributes to query
$attributes = #("displayname","aboutMe","skills","interests","birthday","hireDate")
# Connect to Graph
Connect-MgGraph -Scopes "User.Read.All"
Select-MgProfile -Name beta
# Get list of active users
$users = Get-MgUser -All | Where-Object {($_.AccountEnabled -eq $true) -and ($_.OnPremisesSyncEnabled -eq $true) -and ($_.UserType -eq "Member")}
# Loop through all users and query for SPO profile attributes
$results = #()
foreach ($user in $users) {
$query = Get-MgUser -UserID $user.Id -Select $attributes | Select-Object $attributes
$results += $query
}
# Display Results
$results | Out-GridView
According to the documentation, properties aboutMe, birthday, hireDate, interests, mySite, pastProjects, preferredName, responsibilities, schools, skills, mailboxSettings cannot be returned within a user collection.
They are only supported when retrieving a single user.

Changed user password programmatically by username

I'm am trying to change the password of a given user by their username in a drupal 9 module but I keep getting this error:
Error: Call to a member function setPassword() on array in _password_change()
This is the function I am using:
$userName = 'user1';
$password = 'Password1';
$nid = '1';
function _password_change($userName, $password) {
$user_storage = \Drupal::EntityTypeManager()->getStorage('user');
$user = $user_storage->loadByProperties(['name' => $userName]);
$user->setPassword($password);
$user->save();
}
If I use $user = $user_storage->load($nid); instead of $user = $user_storage->loadByProperties(['name' => $userName]); the code runs fine and the password gets applied successfully unfortunely, the given information will be a username and not the entity id.
The $userName , $password and $nid are set manually for testing proposes.
For what I can tell if I call it using the load id i get back an object but if i call it using the loadByProperties i get back and array hence it can't apply the setPassword function.
What would be a way to load the entity object by the username as an object and be able to apply the new password?
loadByProperties returns an array of entity objects.
So you want call setPassword on the first item in the array which should be your user object.
While you are there, you should also probably check that there was a user with the given username by checking the length of the array returned by loadByProperties.
function _password_change($userName, $password) {
$user_storage = \Drupal::EntityTypeManager()->getStorage('user');
$users = $user_storage->loadByProperties(['name' => $userName]);
// check we got 1 (only 1) user
if (count($users) == 1) {
//get the user from the array.
$user = reset($users);
$user->setPassword($password);
$user->save();
}
}
This code is untested, but you get the idea.

Elastic Search : How to get most researched terms

i m implemeting elasticsearch in a symfony2 project with fos_elastica.
everythings works fine ( indexing data, updating, etc.)
i m currently looking for user behavior analysis : i would like to get the 10 most user searches or keywords in order to re-query it .
for example :
if 45% of searches are about yellow balloons and 45% are about red balloons, i would like to suggest on my homepage some yellow or red balloons
firstly, i was thinking about creating a symfony2 entity to save user search with a timestamp then compute last 1000 searches to get the most famous keywords. although it would surely work , that would be resource killer.
i was wondering if elasticsearch is able to provide these and how to implement it .
i ve read that i could create an index to store my user queries ( and that would be awsome, cause i could use facets to compute them really easily ) , but i don t know how to do save it directly in elastic search from symfony2 without an dedicated entity.
Okay, i finally got it !
here are the different steps :
1) create a new index in config.yml with a specific mapping for your keywords search
in config.yml
indexes:
your_index:
types:
search:
mappings:
value: {type:string}
date : {type:date}
provider: acme\AppBundle\Service\SearchProvider
2) create a new class SearchProvider in Service directory
in acme\Appbundle\Service\SearchProvider
<?php
namespace acme\AppBundle\Service;
use FOS\ElasticaBundle\Provider\ProviderInterface;
use Elastica\Type;
use Elastica\Document;
class SearchProvider implements ProviderInterface
{
protected $searchType;
private $search;
public function __construct(Type $searchType)
{
$this->searchType = $searchType;
}
// the function you will call from your service
public function add( $search )
{
$this->search = $search;
$this->populate();
}
/**
* Insert the repository objects in the type index
*
* #param \Closure $loggerClosure
* #param array $options
*/
public function populate(\Closure $loggerClosure = null, array $options = array())
{
if ($loggerClosure) {
$loggerClosure('Indexing users');
}
$date = time();
$document = new Document();
$document->setData(array('value' => $this->search, 'date' => $date ) );
$this->userType->addDocuments(array($document));
$this->userType->getIndex()->refresh();
}
}
3) create a new service declaration in your service.yml
services:
acme.search_provider:
class: acme\AppBundle\Service\SearchProvider
arguments:
- #fos_elastica.index.recetas.search
tags:
- { name: fos_elastica.provider, index: your_index, type: search }
4) call your service to store new searches like this
$this->get("acme.search_provider")->add("kapoue");
kapoue will be added to the searches.
5) get all the search keywords and rank it with aggregation
$es = $this->get('fos_elastica.index.acme.search');
$query = new \Elastica\Query();
$aggregation = new \Elastica\Aggregation\Terms("top_hits");
$aggregation->setField('value');
$aggregation->setSize( 3 );
$query->addAggregation($aggregation);
$result = $es->search($query);
$mostResearched = $result->getAggregation("top_hits");
print_r ( $mostResearched ); die();

From symfony2 form to a simple form users get incorrect password

Originally creating a normal registration form (email + password) using the symfony form builder i found no problems at all registering my users.
For some technical issues and strategic stuff im not using any more the symfony form builder and i just made a common html form. The username, salt and password gets saved in database but when i tried to login it does not work, so the password or salt are wrong, and that makes me think that maybe the salt is created using a token send as a hidden field created by the symfony form builder, am i right?
So, originally since the symfony form builder allows you to parse the data directly into an entity i did something like this:
if( 'POST' === $this->getRequest( )->getMethod() ) {
$form->bindRequest( $this->getRequest( ) );
if( $form->isValid( ) ) {
$userSignup = $form->getData( );
$user = $userSignup->getUser( );
$user->setPassword( $this->_encodePassword( $user ) );
Now, since im using a normal form:
if(isset($_GET['user_signup']['user']['username']) && $this->_validemail($_GET['user_signup']['user']['username'])) $username = $_GET['user_signup']['user']['username']; else die('BAD EMAIL');
if(isset($_GET['user_signup']['user']['password']) && strlen($_GET['user_signup']['user']['password']) >= 5 && strlen($_GET['user_signup']['user']['password']) <= 20) $password = $_GET['user_signup']['user']['password']; else die('BAD PASSWORD');
$user = new user();
$user->setUsername($username);
$user->setPassword( $this->_encodePassword( $user ) );
The encodePassword function:
protected function _encodePassword( User $user )
{
$factory = $this->get( 'security.encoder_factory' );
$encoder = $factory->getEncoder( $user );
return $encoder->encodePassword( $user->getPassword( ), $user->getSalt( ) );
}
Im re utilizing someone else code so maybe im having trouble understanding how encodePassword works.
If you want registration system in your web application install FOSUserBundle.
Then you can use the userManager for create, register and edit any user.
you should create a salt first (using some random function) and use $user->setSalt($salt) in your controller ...
... or generate the salt inside the User's __construct() method.
FOSUserBundle i.e. creates the salt in the constructor of the User object using:
public function __construct()
{
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
// ...
}
reference here.
Otherwise the encoder called at $this->_encodePassword($user) won't find the salt calling the user object's getter getSalt().
tip:
In symfony2 you should never try to access GET parameters using $_GET ...
... use the Request object instead.
Please read the Symfony2 and HTTP Fundamentals chapter of the book.

How can I query for required fields in a Drupal 7 Database?

I am trying to write a function that will get me the names of the required fields from the drupal database. Then, so I can write one validation function for alerting the user that he/she has not entered in a required field.
You can get this quite easily using the field_info_instances() function:
$instances = field_info_instances('node', 'invoice');
$required = array();
foreach ($instances as $field_name => $instance) {
if ($instance['required'] == 1) {
$required[] = $field_name;
}
}
To get the field type you need to query for the field not the instance. In the loop you can call:
$field = field_info_field($field_name);
$type = $field['type'];

Resources