Azure conditional access object ID translation - azure

Trying to create a simple conditional access policy report,
$Policies = Get-AzureADMSConditionalAccessPolicy
$Policies[1].Conditions.Users.IncludeGroups
These group object ID's can be resolved using:
Get-AzureADObjectByObjectId -ObjectIds xxxx-xxxxx
But how to resolve, for example, locations?
$Policies[1].Conditions.Locations.ExcludeLocations
Could not find the location ID's using Get-AzureADObjectByObjectId.
Any ideas appreciated ...

For the location id's you need to query the namedLocations API rather than the directory itself. For this, use Get-AzureADMSNamedLocationPolicy:
$Policies[1].Conditions.Locations.ExcludeLocations |ForEach-Object {
Get-AzureADMSNamedLocationPolicy -PolicyId $_
}

Related

How do I lookup an existing roleDefinition ID by name using Bicep?

I want to look up the roleDefinition ID in Azure to allow me to use a role name rather than ID - as it is more user friendly
This is what I have tried
param roleDefinitionName string = ''
resource existingRoleDefinition 'Microsoft.Authorization/roleDefinitions#2022-04-01' existing = {
name: 'Storage Blob Data Reader'
}
output test string = 'ID is ${existingRoleDefinition.id}'
The output returned however is
/subscriptions/xxx/resourceGroups/rg-my-ab-h-uks-01/providers/Microsoft.Authorization/roleDefinitions/Storage Blob Data Reader
rather than 2a2b9908-6ea1-4ae2-8e65-a410df84e7d1
Can anyone help?
Currently there's no way to do this in the template language - you can provide your own mapping for built-in roles (which some users do) but that adds a bit of overhead/maintenance so really depends on the problem you're trying to solve to see if that's worth it...

get All resources on azure powershell whose Tags start with (or include) a particular String - Azure Powershell

I have almost 20 resources in azure, 4 of them have been given Tags #
{"Office1work"="work"}
{"Office2practice"="Practice"}
{"Office3practice"="Practice"}
{"Office4practice"="Practice"}
Now I want to get the resources whose Tag names start with the keyword "Office".
I know to get a resource by a TagName,for example "hello", I simply use the following command,
get-azureRmResource -TagName "Hello"
How can I use the -Tagname property of get-azurermresource to give me all resources whose tags are starting with the keyword "Office" ?
Or is there any other good method to get all resources whose Tags start with a particular string?
Thanks :)
You can use this code snippet:
$resources = Get-AzureRmResources
$resources.foreach{ if ($PSItem.tags.keys -match '^Office') { $PSItem } }
First you get all the resources in the subscription, then you filter out all the resource whose tags do not match the 'Office' "expression".
as #LotPings points out, it would probably make more sense to filter without saving to a temporary variable:
$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
Also, I didnt notice you were asking for a starts with filter, so you should use ^Office as a more strict filter (if you need to).

Passing list of values to Cucumber scenario outline

I have a scenario to validate 100 employee names, The QueryString will return them in xml format.All I want to do is to validate all the employee names in an Assertion statement like given below. Instead of adding each name in the Scenario Outline Example, Is it possible to send a list of 100 employee names as input so that I can Iterate through them in java and could easily validate in Assertion condition. Please advice.
Scenario Outline: When the User queries for employee information, the correct records are returned
Given the webservice is running
When the User queries for employee information "<QueryString>"
Then the User receives correct data "<Name>"
Examples:
|QueryString|Name|
|Some localhost url|Peter|
|Some localhost url|Sam|
.
.
#Then("^the User receives correct data\"([^\"]*)\"$")
public void the_user_receives_correct_data(String arg1) throws Throwable {
queryResultPage = selenium.getPageSource();
assertTrue(queryResultPage.contains(arg1));
}
so i will answere here to LINGS comment
What you can do, is use these filenames in your step definition to load the files in your code. Cucumber doesnt support direct file loading as far as i know.
i use something like this to locate full ressource pathes for my relative path file names:
public static String getAbsoluteResourcePath(String resourcePath) {
if (SystemUtils.IS_OS_WINDOWS) {
return Utils.class.getResource(resourcePath).getPath().substring(1).replace("/", File.separator);
} else {
return Utils.class.getResource(resourcePath).getPath().replace("/", File.separator);
}
}
The resourcePath should then be your relative file path
What you are looking for is external test data support, which is supported with QAF. You can use any inbuilt data provider with interceptor to modify data set or custom data provider.
If you are using cucumber version 5+ you can use qaf-cucumber that will give you all qaf features with cucumber. For lower version you can run your existing feature files with QAF runner.

How do you get the value for an attribute when it's not your primary entity

I am trying to write a plugin that will trigger when an account is created. If there is a originating lead I want to fetch the company name in the lead and put it in the account name field. What I'm not sure how to do is to obtain the information out of the lead entity.
I have the following code (I'll keep updating this)...
Entity member = service.Retrieve("lead",
((EntityReference)account["originatingleadid"]).Id, new ColumnSet(true));
if (member.Attributes.Contains("companyname"))
{
companyName = member.Attributes["companyname"].ToString();
}
if (context.PostEntityImages.Contains("AccountPostImage") &&
context.PostEntityImages["AccountPostImage"] is Entity)
{
accountPostImage = (Entity)context.PostEntityImages["AccountPostImage"];
companyName = "This is a test";
if (companyName != String.Empty)
{
accountPostImage.Attributes["name"] = companyName;
service.Update(account);
}
}
I'm not going to spoil the fun for you just yet but the general idea is to:
Catch the message of Create.
Extract the guid from your Entity (that's your created account).
Obtain the guid from its EntityReference (that's your lead).
Read the appropriate field from it.
Update the name field in your account.
Store the information.
Which of the steps is giving you issues? :)
As always, I recommend using query expressions before fetchXML. YMMV
Is lead connected to the account? Just use the IOrganizationService.Retrieve Method
To retrieve the correct lead (assuming you have the lead id from the account entity)..
Create the organizationService in the execute method of your plugin.
http://msdn.microsoft.com/en-us/library/gg334504.aspx
Also here is a nice example to write the plugin:
http://mscrmkb.blogspot.co.il/2010/11/develop-your-first-plugin-in-crm-2011.html?m=1

try to modify a item filed in sharepoint using powershell

this is some code I wrote:
Add-PSSnapin Microsoft.SharePoint.PowerShell
$webURL = "http://nycs00058260/sites/usitp"
$lists = "OsEM1","OsEM2","OsEM3","OsEM4"
$web = Get-SPWeb -Identity "http://nycs00058260/sites/usitp"
foreach($list in $lists)
... ...
Write-Host $item["Title"]
#$item["Item"]=$item["Title"] +" ,"+$webURL+"\"+$filename
$item["Item"]="$tmpValue"+" ,$item[Title]"
$item.Update()
}
}
}
it said: Unable to index into an object of type MicroSoft.SharePoint.SPListItem.
something worong when I change the $item["Item"] value?
There are a few reasons that cause this behavior:
Your permissions don't match what you need to change an item. If you have PowerShell rights, this is often not the case.
Your list is somehow corrupted. This could have something to do with site columns, content types, the list itself, or views. If you created and did not update the list schema (definition), it wouldn't let you edit it.
You don't have AllowUnsafeUpdates set to on for the SPWeb (site) object.
All three of these issues generally have better (matching) error messages but sometimes SharePoint doesn't give you all the information that you need in the error messages.
If you need more details, please ask.

Resources