How to pipeline the username from Get-MoveRequest to Get-MailboxStatistics? - powershell

How do I pipeline the output of Exchange 2010's Get-MoveRequest command so that the Name variable can be used in the $Username variable below?
[CmdletBinding(DefaultParameterSetName = "MoveUser")]
param(
[Parameter(Mandatory = $true, ParameterSetName = "MoveUser", ValueFromPipeline = $true, Position = 0)]
$Username
)
function Get-MBStats($Username )
{
$req = Get-MailboxStatistics -Identity $Username -IncludeMoveHistory
$UserDetail = ($req).MoveHistory[0]
# TODO: SOME CUSTOM STUFF HERE #
New-Object PSObject -Property #{
Username = $Username
Status = $UserDetail.Status
TargetDatabase = $UserDetail.TargetDatabase
CompletionTime = $UserDetail.CompletionTimestamp
MailboxSizeKB = $UserDetail.TotalMailboxSize.ToKB()
DurationSec = $UserDetail.TotalInProgressDuration.TotalSeconds
BadItems = $UserDetail.BadItemsEncountered
}
# Todo: GUI http://msdn.microsoft.com/en-us/magazine/hh288074.aspx #
}
Get-MBStats($Username)
UPDATE
Here are the members output from MoveRequest (source)
TypeName: Microsoft.Exchange.Management.RecipientTasks.MoveRequest
Name MemberType Definition
---- ---------- ----------
Clone Method System.Object Clone()
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetProperties Method System.Object[] GetProperties(System.Collections.Generic.ICollection[Microso...
GetType Method type GetType()
ToString Method string ToString()
Validate Method Microsoft.Exchange.Data.ValidationError[] Validate()
PSComputerName NoteProperty System.String PSComputerName=nycexhc01.nfp.com
RunspaceId NoteProperty System.Guid RunspaceId=dc444c7e-bcac-4c1c-8fdf-847875456c03
Alias Property System.String Alias {get;set;}
BatchName Property System.String BatchName {get;}
Direction Property Microsoft.Exchange.MailboxReplicationService.RequestDirection Direction {get;}
DisplayName Property System.String DisplayName {get;set;}
DistinguishedName Property System.String DistinguishedName {get;}
ExchangeGuid Property System.Guid ExchangeGuid {get;}
ExchangeVersion Property Microsoft.Exchange.Data.ExchangeObjectVersion ExchangeVersion {get;}
ExternalDirectoryObjectId Property System.String ExternalDirectoryObjectId {get;}
Flags Property Microsoft.Exchange.Data.Directory.Recipient.RequestFlags Flags {get;}
Guid Property System.Guid Guid {get;}
Identity Property Microsoft.Exchange.Data.ObjectId Identity {get;}
IsOffline Property System.Boolean IsOffline {get;}
IsValid Property System.Boolean IsValid {get;}
LastExchangeChangedTime Property System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutr...
Name Property System.String Name {get;set;}
OrganizationId Property Microsoft.Exchange.Data.Directory.OrganizationId OrganizationId {get;}
OriginatingServer Property System.String OriginatingServer {get;}
Protect Property System.Boolean Protect {get;}
RecipientType Property Microsoft.Exchange.Data.Directory.Recipient.RecipientType RecipientType {get;}
RecipientTypeDetails Property Microsoft.Exchange.Data.Directory.Recipient.RecipientTypeDetails RecipientTy...
RemoteHostName Property System.String RemoteHostName {get;}
RequestStyle Property Microsoft.Exchange.MailboxReplicationService.RequestStyle RequestStyle {get;}
SourceArchiveDatabase Property Microsoft.Exchange.Data.Directory.ADObjectId SourceArchiveDatabase {get;}
SourceDatabase Property Microsoft.Exchange.Data.Directory.ADObjectId SourceDatabase {get;}
Status Property Microsoft.Exchange.Data.Directory.Recipient.RequestStatus Status {get;}
Suspend Property System.Boolean Suspend {get;}
SuspendWhenReadyToComplete Property System.Boolean SuspendWhenReadyToComplete {get;}
TargetArchiveDatabase Property Microsoft.Exchange.Data.Directory.ADObjectId TargetArchiveDatabase {get;}
TargetDatabase Property Microsoft.Exchange.Data.Directory.ADObjectId TargetDatabase {get;}
Here are the members of the target
TypeName: Microsoft.Exchange.Data.Mapi.MailboxStatistics
Name MemberType Definition
---- ---------- ----------
Clone Method System.Object Clone()
Dispose Method System.Void Dispose()
Equals Method bool Equals(System.Object obj)
GetDisposeTracker Method Microsoft.Exchange.Diagnostics.DisposeTracker GetDisposeTracker()
GetHashCode Method int GetHashCode()
GetProperties Method System.Object[] GetProperties(System.Collections.Generic.ICollection[Microsoft....
GetType Method type GetType()
SuppressDisposeTracker Method System.Void SuppressDisposeTracker()
ToString Method string ToString()
Validate Method Microsoft.Exchange.Data.ValidationError[] Validate()
PSComputerName NoteProperty System.String PSComputerName=nycexhc01.nfp.com
RunspaceId NoteProperty System.Guid RunspaceId=dc444c7e-bcac-4c1c-8fdf-847875456c03
AssociatedItemCount Property System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
Database Property Microsoft.Exchange.Data.ObjectId Database {get;}
DatabaseName Property System.String DatabaseName {get;}
DeletedItemCount Property System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
DisconnectDate Property System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
DisconnectReason Property System.Nullable`1[[Microsoft.Exchange.Data.Mapi.MailboxState, Microsoft.Exchang...
DisplayName Property System.String DisplayName {get;}
Identity Property Microsoft.Exchange.Data.Mapi.MailboxId Identity {get;}
IsArchiveMailbox Property System.Nullable`1[[System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, ...
IsQuarantined Property System.Boolean IsQuarantined {get;}
IsValid Property System.Boolean IsValid {get;}
ItemCount Property System.Nullable`1[[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, P...
LastLoggedOnUserAccount Property System.String LastLoggedOnUserAccount {get;}
LastLogoffTime Property System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
LastLogonTime Property System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,...
LegacyDN Property System.String LegacyDN {get;}
MailboxGuid Property System.Guid MailboxGuid {get;}
MailboxTableIdentifier Property System.String MailboxTableIdentifier {get;}
MapiIdentity Property Microsoft.Exchange.Data.Mapi.MapiObjectId MapiIdentity {get;}
MoveHistory Property System.Object MoveHistory {get;}
ObjectClass Property Microsoft.Exchange.Data.Mapi.ObjectClass ObjectClass {get;}
OriginatingServer Property Microsoft.Exchange.Data.Fqdn OriginatingServer {get;}
ServerName Property System.String ServerName {get;}
StorageLimitStatus Property System.Nullable`1[[Microsoft.Exchange.Data.Mapi.StorageLimitStatus, Microsoft.E...
TotalDeletedItemSize Property Microsoft.Exchange.Data.Unlimited`1[[Microsoft.Exchange.Data.ByteQuantifiedSize...
TotalItemSize Property Microsoft.Exchange.Data.Unlimited`1[[Microsoft.Exchange.Data.ByteQuantifiedSize...

The documentation is not clear on what Get-MoveRequest returns, but something like below is what you can try:
Get-MoveRequest ... | select -expand Name | Get-MBStats

Related

How to query Powershell cmdlet parameter values

How can I get a list possible values of cmdlet parameter programmatically?
E.g for New-Item -Type:
File
Directory
SymbolicLink
Junction
HardLink
Get-Help New-Item -Full
Get-Command New-Item | select *
You can also check the online documentation (e.g. New-Item).
Or you can use
(Get-Command -Name new-item).parametersets
as suggested by vonPryz above.
For "Get-" cmdlets I usually create an object and then do a Get-Member to retrieve the definition of the members.
e.g.
$item = Get-Item .\test.csv
$item | Get-Member
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.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] Target{get=GetTarget;}
AppendText Method System.IO.StreamWriter AppendText()
CopyTo Method System.IO.FileInfo CopyTo(string destFileName), System.IO.FileInfo CopyTo(string destFileName, bool overwrite)
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.AccessControl.FileSecurity GetAccessControl(System.Security.AccessControl.AccessControlSections includeSections)
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetObjectData Method void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context), void ISerializable.GetObjectData(System.Runtime.Serialization.Se...
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(System.IO.FileMode mode, System.IO.FileAccess access), System.IO.FileStream Open(System.IO.FileMode mode, System.I...
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 destinationBackupFileName), System.IO.FileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMe...
SetAccessControl Method void SetAccessControl(System.Security.AccessControl.FileSecurity fileSecurity)
ToString Method string ToString()
PSChildName NoteProperty string PSChildName=test.csv
PSDrive NoteProperty PSDriveInfo PSDrive=C
PSIsContainer NoteProperty bool PSIsContainer=False
PSParentPath NoteProperty string PSParentPath=Microsoft.PowerShell.Core\FileSystem::C:\test
PSPath NoteProperty string PSPath=Microsoft.PowerShell.Core\FileSystem::C:\test\test.csv
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($this.Name.Length - $this.Extension.Length)}else{$this.Name};}
VersionInfo ScriptProperty System.Object VersionInfo {get=[System.Diagnostics.FileVersionInfo]::GetVersionInfo($this.FullName);}

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

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

PowerShell Script selecting for particular value [duplicate]

This question already has answers here:
Powershell script value fetching
(2 answers)
Closed 5 years ago.
How to get a particular value in PowerShell display ?
Example - When I execute below script I get 6 values i need to get only 4th row value.
Command:
Get-WmiObject win32_logicaldisk -Filter "Drivetype=3
Output:
DeviceID : C:
DriveType : 3
ProviderName :
FreeSpace : 183760687104
Size : 255791026176
VolumeName :
I need to fetch only "183760687104" value. How to achieve it. Also I do not want to have FreeSpace tag also. Just plain value "183760687104".
You just access the field by name:
(Get-WmiObject Win32_LogicalDisk -Filter "Drivetype=3").FreeSpace
Note that Get-WmiObject is deprecated, you should be using Get-CimInstance instead.
(Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3").FreeSpace
If you want to save the value in a variable, just assign it:
$freespace = (Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3").FreeSpace
and then you can use $freespace as you wish. Be careful though as on a system with more than one local disk your expression will return an array of values rather than just a single one, so you may want to subscript the result to choose only the first disk. Either of these expressions will be sure to give you a single number:
PS C:\Users\User> (Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3").FreeSpace[0]
94229651456
PS C:\Users\User> (Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3")[0].FreeSpace
94239125504
If you are ever in doubt about the accessible fields on an object, just pipe the expression through gm (short for Get-Member):
Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3" | gm
will list all available fields.
PS C:\Users\User> Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3" | gm
TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_LogicalDisk
Name MemberType Definition
---- ---------- ----------
Clone Method System.Object ICloneable.Clone()
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
GetCimSessionComputerName Method string GetCimSessionComputerName()
GetCimSessionInstanceId Method guid GetCimSessionInstanceId()
GetHashCode Method int GetHashCode()
GetObjectData Method void GetObjectData(System.Runtime.Serialization.SerializationInfo info, Sys...
GetType Method type GetType()
ToString Method string ToString()
Access Property uint16 Access {get;}
Availability Property uint16 Availability {get;}
BlockSize Property uint64 BlockSize {get;}
Caption Property string Caption {get;}
Compressed Property bool Compressed {get;}
ConfigManagerErrorCode Property uint32 ConfigManagerErrorCode {get;}
ConfigManagerUserConfig Property bool ConfigManagerUserConfig {get;}
CreationClassName Property string CreationClassName {get;}
Description Property string Description {get;}
DeviceID Property string DeviceID {get;}
DriveType Property uint32 DriveType {get;}
ErrorCleared Property bool ErrorCleared {get;}
ErrorDescription Property string ErrorDescription {get;}
ErrorMethodology Property string ErrorMethodology {get;}
FileSystem Property string FileSystem {get;}
FreeSpace Property uint64 FreeSpace {get;}
InstallDate Property CimInstance#DateTime InstallDate {get;}
LastErrorCode Property uint32 LastErrorCode {get;}
MaximumComponentLength Property uint32 MaximumComponentLength {get;}
MediaType Property uint32 MediaType {get;}
Name Property string Name {get;}
NumberOfBlocks Property uint64 NumberOfBlocks {get;set;}
PNPDeviceID Property string PNPDeviceID {get;}
PowerManagementCapabilities Property uint16[] PowerManagementCapabilities {get;}
PowerManagementSupported Property bool PowerManagementSupported {get;}
ProviderName Property string ProviderName {get;}
PSComputerName Property string PSComputerName {get;}
Purpose Property string Purpose {get;}
QuotasDisabled Property bool QuotasDisabled {get;}
QuotasIncomplete Property bool QuotasIncomplete {get;}
QuotasRebuilding Property bool QuotasRebuilding {get;}
Size Property uint64 Size {get;}
Status Property string Status {get;}
StatusInfo Property uint16 StatusInfo {get;}
SupportsDiskQuotas Property bool SupportsDiskQuotas {get;}
SupportsFileBasedCompression Property bool SupportsFileBasedCompression {get;}
SystemCreationClassName Property string SystemCreationClassName {get;}
SystemName Property string SystemName {get;}
VolumeDirty Property bool VolumeDirty {get;}
VolumeName Property string VolumeName {get;set;}
VolumeSerialNumber Property string VolumeSerialNumber {get;}
PSStatus PropertySet PSStatus {Status, Availability, DeviceID, StatusInfo}

FilterScript in PowerShell

I'm using Windows Server 2012 R2 with PowerShell v5 and I've stumbled on some PowerShell behaviour I don't understand.
The following line working correctly and returning results as expected:
Get-WindowsFeature | where -Property "InstallState" -eq "Installed"
This working correctly and returning results as previous:
Get-WindowsFeature | where {$_.Installed}
The following is NOT working, even though it should:
Get-WindowsFeature | where {$_.Available}
But this one is working:
Get-WindowsFeature | where -Property "InstallState" -eq "Available"
I've seen the same behaviour with PowerShell v3 on Windows 7 as well.
Please explain it to me.
Get-WindowsFeature | Get-Member -MemberType Property
TypeName: Microsoft.Windows.ServerManager.Commands.Feature
Name MemberType Definition
---- ---------- ----------
AdditionalInfo Property hashtable AdditionalInfo {get;}
BestPracticesModelId Property string BestPracticesModelId {get;}
DependsOn Property string[] DependsOn {get;}
Depth Property int Depth {get;}
Description Property string Description {get;}
DisplayName Property string DisplayName {get;}
EventQuery Property string EventQuery {get;}
FeatureType Property string FeatureType {get;}
Installed Property bool Installed {get;}
InstallState Property Microsoft.Windows.ServerManager.Commands.InstallState InstallState {get;}
Name Property string Name {get;}
Notification Property Microsoft.Windows.ServerManager.ServerComponentManager.Internal.Notification[] Notification {g...
Parent Property string Parent {get;}
Path Property string Path {get;}
PostConfigurationNeeded Property bool PostConfigurationNeeded {get;}
ServerComponentDescriptor Property psobject ServerComponentDescriptor {get;}
SubFeatures Property string[] SubFeatures {get;}
SystemService Property string[] SystemService {get;}
There is no "Available" property.

Powershell: Getting path of A_Script.ps1 execution location

I would like to execute a program.exe which resides next to the script.ps1 file...
How can i get this location/folder?
(this is not a fixed location/folder, can be a usb stick or network drive etc)
I have tried to use
$MyInvocation.MyCommand.Path
But it seems not to be helping me (or i'm not using it the rigth way)
Thanks
This is the pattern I normally use:
$exeName = "MyApplication.exe"
$scriptFolder = Split-Path -Parent $MyInvocation.MyCommand.Path
$exeFullPath = Join-Path -Path $scriptFolder -ChildPath $exeName
$MyInvocation is an automatic variable.
Contains an information about the current command, such as the name,
parameters, parameter values, and information about how the command
was started, called, or "invoked," such as the name of the script that
called the current command.
Note that the object returned by $MyInvocation.MyCommand is different depending upon the context from which it was executed.
The type ScriptInfo is returned from the powershell command window, notice the lack of Path property:
TypeName: System.Management.Automation.ScriptInfo
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
CommandType Property System.Management.Automation.CommandTypes CommandType {get;}
Definition Property System.String Definition {get;}
Module Property System.Management.Automation.PSModuleInfo Module {get;}
ModuleName Property System.String ModuleName {get;}
Name Property System.String Name {get;}
OutputType Property System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Management.Automation.PSTyp...
Parameters Property System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Cult...
ParameterSets Property System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Management.Automation.Comma...
ScriptBlock Property System.Management.Automation.ScriptBlock ScriptBlock {get;}
Visibility Property System.Management.Automation.SessionStateEntryVisibility Visibility {get;set;}
HelpUri ScriptProperty System.Object HelpUri {get=try...
Whereas the type is ExternalScriptInfo when run from a script, notice the additional properties ScriptContents and Path etc.
TypeName: System.Management.Automation.ExternalScriptInfo
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
CommandType Property System.Management.Automation.CommandTypes CommandType {get;}
Definition Property System.String Definition {get;}
Module Property System.Management.Automation.PSModuleInfo Module {get;}
ModuleName Property System.String ModuleName {get;}
Name Property System.String Name {get;}
OriginalEncoding Property System.Text.Encoding OriginalEncoding {get;}
OutputType Property System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Management.Automation.PS...
Parameters Property System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, C...
ParameterSets Property System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Management.Automation.Co...
Path Property System.String Path {get;}
ScriptBlock Property System.Management.Automation.ScriptBlock ScriptBlock {get;}
ScriptContents Property System.String ScriptContents {get;}
Visibility Property System.Management.Automation.SessionStateEntryVisibility Visibility {get;set;}
HelpUri ScriptProperty System.Object HelpUri {get=try...