0

下面的代码显示了拥有许可证的用户,但我还需要知道他们的同步类型是什么,我不确定如何获取该信息

# 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
4

1 回答 1

0

Powershell 中的一切都是对象,因此,它具有方法和属性,正如 LotPings 所评论的,

获取-MsolUser | 获取会员

但这是一个数组,它的属性可能不同,您可以在 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 输出中的属性之一应该是您正在寻找的。

于 2018-09-23T17:33:07.467 回答