I'm completely new to SharePoint 2010 and I'm trying to get a report that looks like this.
Group Name | Subsite or Site Group is used | Group Creation Date | Group Owner
I tried using google for the last three days. So far, I didn't achieve anything.
Please advise.
If you have access to one of the web servers on which SharePoint is running, you can produce a report of that type through PowerShell, such as via the SharePoint 2010 Management Shell.
$web = get-spweb "http://examplesite/exampleweb"
$arr = #()
$web.SiteGroups | %{ $obj = new-object psobject -property #{Name=$_.Name; ParentWeb=$_.ParentWeb; Owner=$_.Owner }; $arr += $obj; }
$arr | Export-Csv -path "C:\Users\username\Desktop\SiteGroups.csv" -NoTypeInformation
Note that this doesn't include the group creation date.
Related
My PowerShell is VERY rusty, so please bear with me. I've been tasked to bulk tag Azure Resources based on CSV data, specifically Azure VM's. In this CSV are 3 headers (VMName, TagName, TagValue). I've tried to automate this task with PowerShell and no matter how I format the code, I keep falling short. Can someone help me clear this up or perhaps point me in the direction of a known working PS script that will help me accomplish this?
`
Connect-AzAccount -TenantId ''
Set-AzContext -Subscription ''
$Import = Import-Csv -Path '...\Tags.csv' |
ForEach-Object {
$_.psobject.properties |
ForEach-Object {Set-Variable -Name $_.Name -Value $_.Tags}
foreach ($Name in $Import) {
$Tag = $_.Name.Tags
$Tag.Add($_.Tags)
Set-AzResource -ResourceId $Name.ResourceId -Tag -Force
}
}
`
I've tried a hash table and a fully customized script. It either only applies the Tag Name and not the Tag Value, and it needs both, or it shoots off error after error. Microsoft seems to want bulk tagging at the subscription and resource group level, so it's a bit difficult to get this right specific to resources. In the end, I want the script to read the server name in Row 1 Column 1, find that resource in Azure, and create the Tag using the Tag Name (Row 1 Column 2) and Tag Value (Row 1 Column 3).
After reproducing from my end, I could able to get this work using New-AzTag. Below is the complete script that worked for me.
$Import = Import-Csv -Path 'Tags.csv'
foreach($I in $Import) {
$Resource = Get-AzResource -Name $I.VMName
$TagName=$I.TagName
$TagValue=$I.TagValue
New-AzTag -ResourceId $Resource.ResourceId -Tag #{"$TagName"="$TagValue"}
}
RESULTS:
Tags.csv
In portal
I am trying to get the user name and the employee ID from Azure Active Directory, but I keep getting a can not match parameter error. See the attached image.
Get-AzADUser -UserPrincipalName $.UserPrincipalName -EmployeeID $.EmployeeID
Parameter Error
I wasn't able to get the employeeId using AdditionalProperties.
Quickest way for me is using the azuread module, as employeeId is not a standard property but and extension, you can get that info using the following command:
get-azureaduser -objectid user#domain | get-azureaduserextension
[1]:Example https://i.stack.imgur.com/uAxz7.png
Also I recommend using graph API to get info from AAD.
https://devblogs.microsoft.com/premier-developer/getting-started-with-graph-api-and-graph-explorer/?msclkid=249a6a28ae7311ec958ae49c7dc811e2
BR
As there is no parameter called EmployeeId in the get-azaduser that's why it gives you the error . The employee Id is stored inside the additional properties.
So if you want to get the AD users name and employee ID you can use the below command :
Get-AzADUser | Select-Object UserprincipalName , #{N="EmployeeId";E={$_.AdditionalProperties["employeeId"]} }
Output:
I needed to grab this attribute and finally got it working:
$user = Get-AzureADUser -SearchString $displayName
$empID = $user.ExtensionProperty.employeeId
I have tried the below and it worked for me.
Get-AzureADUser -top 70000 | ? {$_.AccountEnabled -like $true -and $_.userType -like "Member" -and $_.ExtensionProperty.employeeId -notlike $null } |
select DisplayName,AccountEnabled,Userprincipalname,usertype,#{N="EmployeeID";E={$_.ExtensionProperty.employeeId}}
I have a directory that has about 200k users in it. I need to pull back all the users that came from on-prem AD. This of course would exclude the multiple source guest users. I have to use source because not all users have a usertype.
If there was a way to search Department not equal to null that would work as well, but it doesn't appear to be part of the odata filter standard.
Get-AzureADUser -Filter "Department eq ''" | select DisplayName,`
UserPrincipalName,Mail,creationType,AccountEnabled,Department
To get users that come from on-prem AD you could do something like this
Get-AzureADUser -Filter "dirSyncEnabled eq true"
For selecting only a few, other operators like top can be used as well.. e.g.
Get-AzureADUser -top 5 -Filter "dirSyncEnabled eq true"
To get all users one shot you can do
Get-AzureADUser -All $true -Filter "dirSyncEnabled eq true"
or
Get-AzureADUser -all $true | where-object -property DirSyncEnabled -eq "True"
I have "billing reader" access to several hundred subscriptions in an EA.
I'm trying to get a list of virtual machines and their sizes across all subscriptions.
So currently when I run a "Get-AzureRMSubscription" it shows me all the subscriptions (hundreds of them), but i'm not sure how to actually run a script against all the subscriptions?
Would be great to get a "Get-AzureRMVM" across them all
Any suggestions?
Thanks in advance!
You can possibly do something like this:
$azureSubs = Get-AzureRMSubscription
$azureSubs | ForEach-Object {Select-AzureRMSubscription $_ | Out-Null; Get-AzureRMVM -WarningAction SilentlyContinue}
You are essentially setting an array variable to hold all your Azure Subscription and piping it to the ForEach-Object cmdlet to iterate all of the objects in the array. Then you pipe it to the Get-AzureRMVM cmdlet to list all VMs in each subscription.
This is definitely not optimized for performance and there might be better solutions out there, but at least you can run it and forget it.
The reason for the Out-Null and -WarningAction is to suppress the outputs you do not need.
You didn't ask but for classic resources we have the following script run on a regular basis and its output stored in a SQL Database.
$subscriptions = Get-AzureSubscription
foreach ($sub in $subscriptions)
{
$sub | Select-AzureSubscription
Get-AzureService | % {
Get-AzureDeployment -ServiceName $_.ServiceName
} | % {
New-Object -TypeName 'PSObject' -Property #{ 'ServiceName' = $_.ServiceName; 'Addresses' = $_.VirtualIPs.Address; }
} | sort Addresses | ft
}
% is ForEach-Object, ft is Format-Table although some kind souls may come along and try to edit this and make it harder to reuse. You can add/remove properties in the select statement to tailor your output as needed. Try it in one subscription to refined your needs, then create a script to make it easy to reuse.
We recently released Azure Resource Graph to support these types of searches across multiple subscriptions. See documentation here https://learn.microsoft.com/en-us/azure/governance/resource-graph/overview
In my PowerShell script, I want to get the SPWebTemplate which has been used to create a SPWeb. In SPWeb instances, properties WebTemplate and WebTemplateId are accessible, but both of them dont identify a SPWebTemplate uniquely.
For example, if the SPWebTemplate "STS#0" has been used to create a SPWeb, WebTemplate would contain "STS" and WebTemplateId be "1".
Now
Get-SPWebTemplate | where { $_.ID -eq 1 }
would result in 3 results for each installed language (STS#0, STS#1, STS#2). How can I retrieve the correct SPWebTemplate-Name (STS#1)?
Thanks in advance,Jonas
Try SPWeb.Configuration.
This property has to be in the running for Most Poorly Named Property - SharePoint API. I remember trying to use WebTemplateId myself until I found Configuration (and I don't remember how I eventually found it).
You can try
$web = Get-SPWeb http://site/subsite
Get-SPWebTemplate | where {$_.name -like $web.WebTemplate+"*" } | where {$_.name -like "*"+$web.Configuration }
$web.Dispose()
But keep in mind that some $web.Configuration can be -1.