why did the catch block
$ComputerName = "server"
try {
#Hostname Abfragen der fürs CMI Query passt
$OptDCOM = New-CimSessionOption -Protocol Dcom
$CimSessionDCOM = New-CimSession -ComputerName $ComputerName -SessionOption $OptDCOM
}
catch{
Write-Host "Fehler beim CIM-Instance mit DCOM: $ComputerName"
$array += $_.Exception.Message
$BS = "PSR"
}
$BS
doesnt trigger ? got the following error:
New-CimSession : Der RPC-Server ist nicht verfügbar.
In Zeile:6 Zeichen:23
+ ... ssionDCOM = New-CimSession -ComputerName $ComputerName -SessionOption ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-CimSession], CimException
+ FullyQualifiedErrorId : HRESULT 0x800706ba,Microsoft.Management.Infrastructure.CimCmdlets.NewCimSessionCommand
+ PSComputerName :
But nothing in the catch-Block happen, i need to change to PS-Remoting when this above failed.
Thanks
Add -ErrorAction Stop
$CimSessionDCOM = New-CimSession -ComputerName $ComputerName -SessionOption $OptDCOM -ErrorAction Stop
User contributions licensed under CC BY-SA 3.0