Help with PowerShell Script
Budget: $10 – $30 USD
I have a powershell script that launches an executable with parameters. The parameters for the executable conflict because the parameters are also expressions used by powershell.
Last line in the script below:
$LocalPath="$Env:USERPROFILE\AppData\Local\Microsoft\Outlook\RoamCache"
$RoamCache = "HKCU:\Software\Microsoft\Office\16.0\Outlook\Perf\RoamingStreamsCache"
$Outlook = New-Object -ComObject Outlook.Application
$namespace = $Outlook.GetNameSpace("MAPI")
$name = 'MsgEID'
$keys = @( (Get-ChildItem $RoamCache -Recurse | Where-Object {$_.Property -eq $name}).name )
$NewAutoCompleteFilename = ""
#Loop through the RoamingStreamsCache entries to find one matching the hidden AutoComplete entry from the account, if it exists at this point.
foreach($key in $keys)
{
$key = $key.Replace("HKEY_CURRENT_USER\","HKCU:\")
$value = (get-itemproperty -path $key -name $name).$name
$MsgID = ""
#Convert the value to Hex for lookup
foreach ($v in $value) { $MsgID = $MsgID + '{0:X2}' -f $v }
$CacheItem = ""
try
{
# write-host "$($Key.Split('\')[-1])" -ForegroundColor Yellow #Verifying information
$CacheItem = $namespace.GetItemFromID($MsgID)
if($CacheItem.Subject -eq "IPM.Configuration.Autocomplete")
{
$NewAutoCompleteFilename = "Stream_Autocomplete_0_$($Key.Split('\')[-1]).dat"
}
}
catch
{
#I don't really care if the item isn't found. It could be in a different mailbox since these are all stored together rather than in the profile.
# write-host "error" -ForegroundColor Red #Verifying information
}
If($NewAutoCompleteFilename) { break } #Found it...don't need to do any more work here.
}
.\NK2Edit.exe /LogFile "mylog2.txt" /script_express "$LocalPath\$NewAutoCompleteFilename" 'If Domain Equal "ci.com" Delete'
Last line in the script below:
$LocalPath="$Env:USERPROFILE\AppData\Local\Microsoft\Outlook\RoamCache"
$RoamCache = "HKCU:\Software\Microsoft\Office\16.0\Outlook\Perf\RoamingStreamsCache"
$Outlook = New-Object -ComObject Outlook.Application
$namespace = $Outlook.GetNameSpace("MAPI")
$name = 'MsgEID'
$keys = @( (Get-ChildItem $RoamCache -Recurse | Where-Object {$_.Property -eq $name}).name )
$NewAutoCompleteFilename = ""
#Loop through the RoamingStreamsCache entries to find one matching the hidden AutoComplete entry from the account, if it exists at this point.
foreach($key in $keys)
{
$key = $key.Replace("HKEY_CURRENT_USER\","HKCU:\")
$value = (get-itemproperty -path $key -name $name).$name
$MsgID = ""
#Convert the value to Hex for lookup
foreach ($v in $value) { $MsgID = $MsgID + '{0:X2}' -f $v }
$CacheItem = ""
try
{
# write-host "$($Key.Split('\')[-1])" -ForegroundColor Yellow #Verifying information
$CacheItem = $namespace.GetItemFromID($MsgID)
if($CacheItem.Subject -eq "IPM.Configuration.Autocomplete")
{
$NewAutoCompleteFilename = "Stream_Autocomplete_0_$($Key.Split('\')[-1]).dat"
}
}
catch
{
#I don't really care if the item isn't found. It could be in a different mailbox since these are all stored together rather than in the profile.
# write-host "error" -ForegroundColor Red #Verifying information
}
If($NewAutoCompleteFilename) { break } #Found it...don't need to do any more work here.
}
.\NK2Edit.exe /LogFile "mylog2.txt" /script_express "$LocalPath\$NewAutoCompleteFilename" 'If Domain Equal "ci.com" Delete'