How to get users that sync type is cloud and get their license information in o365 - Powershell

50 views Asked by At

The code below shows the users with licenses but I need to know what their sync type is as well and I am unsure how to get that information

# Connect to o365 tenant

Connect-MsolService

# Get all users in o365 and get license information
$groupOfUsers = Get-MsolUser -all  

$results = foreach ($user in $groupOfUsers) {
$licenses = $user.licenses.accountskuid
    foreach ($license in $licenses) {
    [pscustomobject]@{
        UPN = $user.userprincipalname
        License = $license

        }
  }
 }

 # Export the results to csv
 $results | Export-Csv c:\scripts\UsersWitho365licenses.csv -NoTypeInformation
1

There are 1 answers

0
Roque Sosa On

Everything in Powershell is an object, therefore, it has methods and properties, and as LotPings commented,

Get-MsolUser | Get-Member

But this is an array which may differ on the properties an methods you will be able to use in the foreach. Try this (I will do it with FileItems as I don't have that module):

cd $HOME

$files = Get-ChildItem

$files | Get-Member

Result:

    TypeName: System.IO.DirectoryInfo

Name                      MemberType     Definition                                                                         
----                      ----------     ----------                                                                         
LinkType                  CodeProperty   System.String LinkType{get=GetLinkType;}                                           
Mode                      CodeProperty   System.String Mode{get=Mode;}                                                      
Target                    CodeProperty   System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=4.0.0...
Create                    Method         void Create(), void Create(System.Security.AccessControl.DirectorySecurity direc...
CreateObjRef              Method         System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)                    
CreateSubdirectory        Method         System.IO.DirectoryInfo CreateSubdirectory(string path), System.IO.DirectoryInfo...
Delete                    Method         void Delete(), void Delete(bool recursive)                                         
EnumerateDirectories      Method         System.Collections.Generic.IEnumerable[System.IO.DirectoryInfo] EnumerateDirecto...
EnumerateFiles            Method         System.Collections.Generic.IEnumerable[System.IO.FileInfo] EnumerateFiles(), Sys...
EnumerateFileSystemInfos  Method         System.Collections.Generic.IEnumerable[System.IO.FileSystemInfo] EnumerateFileSy...
Equals                    Method         bool Equals(System.Object obj)                                                     
GetAccessControl          Method         System.Security.AccessControl.DirectorySecurity GetAccessControl(), System.Secur...
GetDirectories            Method         System.IO.DirectoryInfo[] GetDirectories(), System.IO.DirectoryInfo[] GetDirecto...
GetFiles                  Method         System.IO.FileInfo[] GetFiles(string searchPattern), System.IO.FileInfo[] GetFil...
GetFileSystemInfos        Method         System.IO.FileSystemInfo[] GetFileSystemInfos(string searchPattern), System.IO.F...
GetHashCode               Method         int GetHashCode()                                                                  
GetLifetimeService        Method         System.Object GetLifetimeService()                                                 
GetObjectData             Method         void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.R...
GetType                   Method         type GetType()                                                                     
InitializeLifetimeService Method         System.Object InitializeLifetimeService()                                          
MoveTo                    Method         void MoveTo(string destDirName)                                                    
Refresh                   Method         void Refresh()                                                                     
SetAccessControl          Method         void SetAccessControl(System.Security.AccessControl.DirectorySecurity directoryS...
ToString                  Method         string ToString()                                                                  
PSChildName               NoteProperty   string PSChildName=.dotnet                                                         
PSDrive                   NoteProperty   PSDriveInfo PSDrive=C                                                              
PSIsContainer             NoteProperty   bool PSIsContainer=True                                                            
PSParentPath              NoteProperty   string PSParentPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\Ras_T           
PSPath                    NoteProperty   string PSPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\Ras_T\.dotnet         
PSProvider                NoteProperty   ProviderInfo PSProvider=Microsoft.PowerShell.Core\FileSystem                       
Attributes                Property       System.IO.FileAttributes Attributes {get;set;}                                     
CreationTime              Property       datetime CreationTime {get;set;}                                                   
CreationTimeUtc           Property       datetime CreationTimeUtc {get;set;}                                                
Exists                    Property       bool Exists {get;}                                                                 
Extension                 Property       string Extension {get;}                                                            
FullName                  Property       string FullName {get;}                                                             
LastAccessTime            Property       datetime LastAccessTime {get;set;}                                                 
LastAccessTimeUtc         Property       datetime LastAccessTimeUtc {get;set;}                                              
LastWriteTime             Property       datetime LastWriteTime {get;set;}                                                  
LastWriteTimeUtc          Property       datetime LastWriteTimeUtc {get;set;}                                               
Name                      Property       string Name {get;}                                                                 
Parent                    Property       System.IO.DirectoryInfo Parent {get;}                                              
Root                      Property       System.IO.DirectoryInfo Root {get;}                                                
BaseName                  ScriptProperty System.Object BaseName {get=$this.Name;}                                           


   TypeName: System.IO.FileInfo

Name                      MemberType     Definition                                                                         
----                      ----------     ----------                                                                         
LinkType                  CodeProperty   System.String LinkType{get=GetLinkType;}                                           
Mode                      CodeProperty   System.String Mode{get=Mode;}                                                      
Target                    CodeProperty   System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=4.0.0...
AppendText                Method         System.IO.StreamWriter AppendText()                                                
CopyTo                    Method         System.IO.FileInfo CopyTo(string destFileName), System.IO.FileInfo CopyTo(string...
Create                    Method         System.IO.FileStream Create()                                                      
CreateObjRef              Method         System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)                    
CreateText                Method         System.IO.StreamWriter CreateText()                                                
Decrypt                   Method         void Decrypt()                                                                     
Delete                    Method         void Delete()                                                                      
Encrypt                   Method         void Encrypt()                                                                     
Equals                    Method         bool Equals(System.Object obj)                                                     
GetAccessControl          Method         System.Security.AccessControl.FileSecurity GetAccessControl(), System.Security.A...
GetHashCode               Method         int GetHashCode()                                                                  
GetLifetimeService        Method         System.Object GetLifetimeService()                                                 
GetObjectData             Method         void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.R...
GetType                   Method         type GetType()                                                                     
InitializeLifetimeService Method         System.Object InitializeLifetimeService()                                          
MoveTo                    Method         void MoveTo(string destFileName)                                                   
Open                      Method         System.IO.FileStream Open(System.IO.FileMode mode), System.IO.FileStream Open(Sy...
OpenRead                  Method         System.IO.FileStream OpenRead()                                                    
OpenText                  Method         System.IO.StreamReader OpenText()                                                  
OpenWrite                 Method         System.IO.FileStream OpenWrite()                                                   
Refresh                   Method         void Refresh()                                                                     
Replace                   Method         System.IO.FileInfo Replace(string destinationFileName, string destinationBackupF...
SetAccessControl          Method         void SetAccessControl(System.Security.AccessControl.FileSecurity fileSecurity)     
ToString                  Method         string ToString()                                                                  
PSChildName               NoteProperty   string PSChildName=.bash_history                                                   
PSDrive                   NoteProperty   PSDriveInfo PSDrive=C                                                              
PSIsContainer             NoteProperty   bool PSIsContainer=False                                                           
PSParentPath              NoteProperty   string PSParentPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\Ras_T           
PSPath                    NoteProperty   string PSPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\Ras_T\.bash_history   
PSProvider                NoteProperty   ProviderInfo PSProvider=Microsoft.PowerShell.Core\FileSystem                       
Attributes                Property       System.IO.FileAttributes Attributes {get;set;}                                     
CreationTime              Property       datetime CreationTime {get;set;}                                                   
CreationTimeUtc           Property       datetime CreationTimeUtc {get;set;}                                                
Directory                 Property       System.IO.DirectoryInfo Directory {get;}                                           
DirectoryName             Property       string DirectoryName {get;}                                                        
Exists                    Property       bool Exists {get;}                                                                 
Extension                 Property       string Extension {get;}                                                            
FullName                  Property       string FullName {get;}                                                             
IsReadOnly                Property       bool IsReadOnly {get;set;}                                                         
LastAccessTime            Property       datetime LastAccessTime {get;set;}                                                 
LastAccessTimeUtc         Property       datetime LastAccessTimeUtc {get;set;}                                              
LastWriteTime             Property       datetime LastWriteTime {get;set;}                                                  
LastWriteTimeUtc          Property       datetime LastWriteTimeUtc {get;set;}                                               
Length                    Property       long Length {get;}                                                                 
Name                      Property       string Name {get;}                                                                 
BaseName                  ScriptProperty System.Object BaseName {get=if ($this.Extension.Length -gt 0){$this.Name.Remove(...
VersionInfo               ScriptProperty System.Object VersionInfo {get=[System.Diagnostics.FileVersionInfo]::GetVersionI...

But You don't care about all that you just want the properties, you can get them like this:

$fileItem = $files[0]
$fileItem | Get-Member -

Result:

TypeName: System.IO.DirectoryInfo

Name              MemberType     Definition                                                                                 
----              ----------     ----------                                                                                 
LinkType          CodeProperty   System.String LinkType{get=GetLinkType;}                                                   
Mode              CodeProperty   System.String Mode{get=Mode;}                                                              
Target            CodeProperty   System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=4.0.0.0, Cult...
PSChildName       NoteProperty   string PSChildName=.dotnet                                                                 
PSDrive           NoteProperty   PSDriveInfo PSDrive=C                                                                      
PSIsContainer     NoteProperty   bool PSIsContainer=True                                                                    
PSParentPath      NoteProperty   string PSParentPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\Ras_T                   
PSPath            NoteProperty   string PSPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\Ras_T\.dotnet                 
PSProvider        NoteProperty   ProviderInfo PSProvider=Microsoft.PowerShell.Core\FileSystem                               
Attributes        Property       System.IO.FileAttributes Attributes {get;set;}                                             
CreationTime      Property       datetime CreationTime {get;set;}                                                           
CreationTimeUtc   Property       datetime CreationTimeUtc {get;set;}                                                        
Exists            Property       bool Exists {get;}                                                                         
Extension         Property       string Extension {get;}                                                                    
FullName          Property       string FullName {get;}                                                                     
LastAccessTime    Property       datetime LastAccessTime {get;set;}                                                         
LastAccessTimeUtc Property       datetime LastAccessTimeUtc {get;set;}                                                      
LastWriteTime     Property       datetime LastWriteTime {get;set;}                                                          
LastWriteTimeUtc  Property       datetime LastWriteTimeUtc {get;set;}                                                       
Name              Property       string Name {get;}                                                                         
Parent            Property       System.IO.DirectoryInfo Parent {get;}                                                      
Root              Property       System.IO.DirectoryInfo Root {get;}                                                        
BaseName          ScriptProperty System.Object BaseName {get=$this.Name;}

One of the properties in the output of Get-Member should be what you are looking for.