Have this piece of code. the aim to cycle through PC, looking PST files. would also like to indicate if no PST files found so line in CSV is not blank
there is a catch statement for when the PC is off line, sets every thing to $Null
$session = New-CimSession -ComputerName $Computer -Credential $Credential
$PSTs = Get-CimInstance -CimSession $Session -ClassName CIM_DataFile -Filter "Drive='C:' and Extension='pst'" | Select Name, Status, LastAccessed, FileSize, InstallDate
Foreach($PST in $PSTs){
try{
$Properties = [Ordered]@{
'Computer Name' = $Computer
'Is On Line' = 'Yes'
'Scan Date' = $TimeStamp
'PST Name' = if(!($PSTs)){'NO PST FIles Found'}Else{$PST.Name}
'PST Size(Gb)' = [MAth]::Round($PST.FileSize/1gb,2)
'PST Status' = $PST.Status
'PST Creation Date' = $PST.InstallDate
'PST Last Accessed' = $PST.LastAccessed
}
This line ‘PST Name’ = if(!($PSTs)){‘NO PST FIles Found’}Else{$PST.Name} doesnt work when object is empty.
Have tried if(!($PST))… same result.
the following lines code produce the correct result.
if(!(PSTs)){
write-warning “No PST files found”
}
However I would like to include in the object for output to CSV.
any assistance would be greatly appreciated
thanks in advance
Peter