# replace server name to some server that you control $server = 'SOMESERVER1'
# Get-CimInstance uses WinRM remoting by default Get-CimInstance-ClassName Win32_BIOS -ComputerName$server
# telling Get-CimInstance to use the old DCOM to contact an old system $options = New-CimSessionOption-Protocol Dcom $session = New-CimSession-SessionOption$options-ComputerName$server Get-CimInstance-ClassName Win32_BIOS -CimSession$session Remove-CimSession-CimSession$session
# we are comparing this WMI class (feel free to adjust) $wmiClass = 'Win32_OperatingSystem'
# get information about the WMI class Win32_OperatingSystem with both cmdlets $a = Get-WmiObject-Class$wmiClass | Select-Object-First1 $b = Get-CimInstance-ClassName$wmiClass | Select-Object-First1
# create a calculated property that returns only the basic type name # and omits the namespace $typeName = @{ Name = 'Type' Expression = { $type = $_.TypeNameOfValue.Split('.')[-1].ToLower() switch ($type) { 'boolean' { 'bool' } default { $type } } } }
# ignore the metadata properties which we already know are different $meta = '__CLASS','__DERIVATION','__DYNASTY','__GENUS','__NAMESPACE','__PATH','__PROPERTY_COUNT','__RELPATH','__SERVER','__SUPERCLASS','CimClass','CimInstanceProperties','CimSystemProperties','ClassPath','Container','Options','Properties','Qualifiers','Scope','Site','SystemProperties'
# return the properties and their data type. Add the origin so we later know # which cmdlet emitted them $aDetail = $a.PSObject.Properties | # exclude the metadata we already know is different Where-Object { $_.Name -notin$meta } | # add the origin command as new property "Origin" Select-Object-Property Name, $typeName, @{N='Origin';E={'Get-WmiObject'}} $bDetail = $b.PSObject.Properties | # exclude the metadata we already know is different Where-Object { $_.Name -notin$meta } | # add the origin command as new property "Origin" Select-Object-Property Name, $typeName, @{N='Origin';E={'Get-CimInstance'}}
# compare differences Compare-Object-ReferenceObject$aDetail-DifferenceObject$bDetail-Property Name, Type-PassThru | Select-Object-Property Name, Origin, Type | Sort-Object-Property Name
# we are comparing this WMI class (feel free to adjust) $wmiClass = 'Win32_OperatingSystem'
# get information about the WMI class Win32_OperatingSystem with both cmdlets $a = Get-WmiObject-Class$wmiClass | Select-Object-First1 $b = Get-CimInstance-ClassName$wmiClass | Select-Object-First1
# dump the property names and add the property "Origin" so you know # which property was returned by which command: $aDetail = $a.PSObject.Properties | Select-Object-Property Name, @{N='Origin';E={'Get-WmiObject'}} $bDetail = $b.PSObject.Properties | Select-Object-Property Name, @{N='Origin';E={'Get-CimInstance'}}
# compare the results: Compare-Object-ReferenceObject$aDetail-DifferenceObject$bDetail-Property Name -PassThru | Sort-Object-Property Origin
functionConvert-WordDocument { param ( # accept path strings or items from Get-ChildItem [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] [string] [Alias('FullName')] $Path )
begin { # we are collecting all paths first [Collections.ArrayList]$collector = @() }
process { # find extension $extension = [System.IO.Path]::GetExtension($Path)
# we only process .doc and .dot files if ($extension-eq'.doc'-or$extension-eq'.dot') { # add to list for later processing $null = $collector.Add($Path)
} } end { # pipeline is done, now we can start converting!
# conversion cannot work for read-only docs If (!$doc.ActiveWindow.View.ReadingLayout) { if ($targetConversion-gt0) { $pathOut = [IO.Path]::ChangeExtension($Path, $targetExtension)