Как получить пользователей с таким типом синхронизации в облаке и получить информацию о лицензии в o365 - Powershell - PullRequest
0 голосов
/ 21 сентября 2018

Приведенный ниже код показывает пользователей с лицензиями, но мне нужно знать, каков их тип синхронизации, и я не уверен, как получить эту информацию

# 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 Ответ

0 голосов
/ 23 сентября 2018

Все в Powershell является объектом, поэтому у него есть методы и свойства, и, как прокомментировал LotPings,

Get-MsolUser |Get-Member

Но это массив, который может отличаться по свойствам и методам, которые вы сможете использовать в foreach.Попробуйте это (я сделаю это с FileItems, так как у меня нет этого модуля):

cd $HOME

$files = Get-ChildItem

$files | Get-Member

Результат:

    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...

Но Вас не волнует все, что вы простоЕсли вы хотите получить свойства, вы можете получить их следующим образом:

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

Результат:

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;}

Одним из свойств в выводе Get-Member должно быть то, что вы ищете.

...