Wednesday, May 11, 2016

Use SCCM to Query WMI (Hardware or OS information)



One of the best features of SCCM is the query function. They didn't cover it when I took the class but this can make your day.

Step 1 - The setup:

In Administration > Client Settings > Default Client Settings (or wherever) > Properties

 

Select Hardware Inventory > Set Classes...


These are essentially WMI classes. You should at least pick:


Picking these will let you write queries for software installed on machines. There are thousands of pieces of information in there. If you ever need data collected from your OS or hardware this should be first place to check. You can also get custom MOF files to collect information not in WMI or specific to your hardware from vendors.


Step 2 - Writing the Query:

Once the inventory has ran... You can query it.

Go to Monitoring > Queries > Create Query


Name it then click edit query statement


Now in edit query statement click the sun? button highlighted in yellow below



Select how you want it sorted. Then press Select....



Add The System Resource attribute Name



The result should be something like this



Now comes the fun part add additional criteria by clicking the Sun? (New) button and following the same steps to add almost any WMI class you want.



Hold on! I don't have local admins that would so useful for auditing! I know right... Follow this blog post and you will. https://blogs.technet.microsoft.com/sudheesn/2014/12/12/collect-hardware-inventory-of-local-admins/





SharePoint 2010 Calculated Hyper Links


Normally if I wanted to use a hyperlink column in SharePoint I would create a workflow that sets the URL then shortens the description. Like this:



There is a much better way....

Create 2 single line of text columns one title URL another titled URL Description.
Create a third calculated column with this formula:

="<a href='"&URL&"'>"&[URL Description]&"</a>"

Set the data type to Number.




The result is a pretty hyperlink


Ping Back: https://devdotnotes.wordpress.com/2012/01/29/sharepoint-caculated-column-and-hyperlink-no-workflow-or-script-needed/

Monday, May 9, 2016

Get Group Members via PowerShell


Awhile back I was tasked with reporting and validating SharePoint 2010 permissions. In 2010 you pretty much have to buy a product to do this.... I decided to instead switch to all active directory based permissions so I could export the group members and generate a report. You could in use this script to get any group membership. I just point this one at my SharePoint OU highlighted in red. You would obviously need to change the search base for your active directory. 

Import-Module ActiveDirectory

$Groups = (Get-ADGroup -Properties * -Filter * -SearchBase "OU=SharePoint 2010,OU=SharePoint,DC=CHANGETHIS,DC=com" | select name,description)
$Table = @()
$Record = @{
"Group Name" = ""
"Group Description" = ""
"Name" = ""
"Username" = ""
"Title" = ""
}

Foreach ($group in $Groups.name)
{
$Arrayofmembers = Get-ADGroupMember -Identity $group -Recursive| Where-Object { $_.objectClass -eq 'user' } | Get-ADUser -Properties *
foreach ($Member in $Arrayofmembers)
{
$adgroupdesc = Get-ADGroup $group -properties * | select description,managedby
$groupdesc = $adgroupdesc.description
if ($groupdesc -eq $null) {$groupdesc = "No Description"}

$adgroupowner = $adgroupdesc.managedby
if ($adgroupowner -eq $null) {$adgroupownername = "No Owner"} else {
$adgroupownername = Get-ADUser $adgroupowner -Properties description}

$groupowner = $adgroupownername
$Record."Group Name" = $Group
$Record."Group Description" = $groupdesc
$Record."Name" = $Member.name
$Record."UserName" = $Member.description
$Record."Title" = $Member.title
$Obj=New-Object PSObject
    $Obj | Add-Member -Name "Group Name" -MemberType NoteProperty  -Value $Group 
    $Obj | Add-Member -Name "Group Description" -MemberType NoteProperty  -Value $groupdesc
    $Obj | Add-Member -Name "Group Owner" -MemberType NoteProperty  -Value $adgroupownername
    $Obj | Add-Member -Name "Name" -MemberType NoteProperty -Value $Member.name
    $Obj | Add-Member -Name "Username" -MemberType NoteProperty -Value $Member.description
    $Obj | Add-Member -Name "Title" -MemberType NoteProperty -Value $Member.Title
$Table += $obj

}

}

$Table | export-csv "C:\Temp\SharePoint_Security_Groups.csv" -NoTypeInformation

Get All Active Directory Users with PowerShell

CSVDE is Terrible

This command:
csvde -f c:\Temp\AD_Users.csv  -r "(&(objectCategory=person)(objectClass=user))"  -l physicalDeliveryOfficeName,description,cn,sn,givenname,lastlogintimestamp,homeDirectory,dn,memberof,title
will give you every AD user but it sometimes puts columns where it wants and doesn't allow you to sort in the command.

I decided to write this in PowerShell instead and here is what I came up with...

Import-Module ActiveDirectory

$Table = @()


$Arrayofmembers = Get-ADUser -filter {objectClass -eq "user"}  -searchbase "DC=CHANGETHIS,DC=com" -Properties * | Sort-Object -Property cn | select physicaldeliveryofficename,employeeID,description,cn,sn,givenname,lastlogondate,displayname,title,Manager,DistinguishedName,altRecipient, @{n=’MemberOf’; e= { ( $_.memberof | % { (Get-ADObject $_).Name }) -join “;” }} | Sort-Object -Property Name 

Foreach($User in $Arrayofmembers) {



$Obj=New-Object PSObject
    $Obj | Add-Member -Name "displayname" -MemberType NoteProperty  -Value $User.displayname
    $Obj | Add-Member -Name "physicaldeliveryofficename" -MemberType NoteProperty  -Value $User.physicaldeliveryofficename
    $Obj | Add-Member -Name "employeeID" -MemberType NoteProperty  -Value $User.employeeID
    $Obj | Add-Member -Name "description" -MemberType NoteProperty  -Value $User.description
    $Obj | Add-Member -Name "cn" -MemberType NoteProperty  -Value $User.cn
    $Obj | Add-Member -Name "sn" -MemberType NoteProperty  -Value $User.sn
    $Obj | Add-Member -Name "givenname" -MemberType NoteProperty  -Value $User.givenname
    $Obj | Add-Member -Name "lastlogondate" -MemberType NoteProperty  -Value $User.lastlogondate
    $Obj | Add-Member -Name "title" -MemberType NoteProperty  -Value $User.title
    $Obj | Add-Member -Name "Manager" -MemberType NoteProperty  -Value $User.Manager
    $Obj | Add-Member -Name "DN" -MemberType NoteProperty  -Value $User.DistinguishedName
    $Obj | Add-Member -Name "altRecipient" -MemberType NoteProperty  -Value $User.altRecipient
    $Obj | Add-Member -Name "MemberOf" -MemberType NoteProperty  -Value $User.MemberOf
$Table += $obj

}

$Table | export-csv "c:\Temp\ADUsers.csv" -NoTypeInformation