I've never seen this one, and a search didn't find this issue. A script that ran last week this way with output is silently failing this week. I checked the file has read/wright/run checked in windows explorer. I tried set-executionpolicy remotesigned at the PS prompt.
This script is run at the windows command prompt like this:
powershell "powershell.exe {c:\temp\crashAfter.ps1}"
(no results)
The other ways I've tried are:
powershell
set-executionpolicy remotesigned
.\crashAfter.ps1
(no results)
I've also tried:
PowerShell -File c:\temp\crashAfter.ps1
(no results both at powershell prompt and at just regular windows command line)
What could cause powershell to fail silently like this? It works to go to the powershell prompt at the command line.
This is the script, which hasn't changed since last time I ran it:
$today=[system.datetime](Get-Date)
$startTime=$today.AddHours(-4)
$events = Get-WinEvent -FilterHashtable #{LogName='Application';ProviderName='Application Error';Data='SearchUI.exe';StartTime=$($startTime);EndTime=$($today);} -ErrorAction SilentlyContinue
foreach ($event in $events)
{
$crashOccurredTime=$event.TimeCreated
$lookForInitStart = $event.TimeCreated.AddMinutes(-2)
$eventInit = {Get-WinEvent -FilterHashtable #{LogName='Application';ProviderName='Application Error';StartTime=$lookForInitStart;EndTime=$crashOccurredTime;} -ErrorAction SilentlyContinue | Where-Object -PipelineVariable Message -Match 'SearchUI'
}
if($eventInit -ne $null)
{
Write-Host "Found SearchUI.exe after SearchUI TimeCreated $($event.TimeCreated) ProviderName $($event.ProviderName) Message $($event.Message)"
}
else
{
Write-Host "none"
}
}
Last Friday when I ran this script, it was using our application that we can use to run scripts, and my results looked like this (not sure what CLIXML is):
#< CLIXML
Found SearchUI.exe after SearchUI TimeCreated 08/08/2022 13:46:45 ProviderName Application Error Message
...
So I am working on a powershell script that will delete suspected phishing emails from emails mailboxes across the org that match a certain subject line and date. To have the script work i need it to loop at the Get-ComplianceSearch -Identity xxxx part until the status equals complete, but I cannot seem to get it to work and I am not the greatest at powershell. Here is what I have so far:
#it is probably easiest to open this script in Powershell ISE so you can edit the parameters that will match whatever email needs to be deleted
Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned
#You will enter your main account username and password(not su, since it has to be an active mail account)
$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://XXX-XXXX/powershell/ -Credential $LiveCred
Import-PSSession $Session -AllowClobber
#You should now be logged into XXX-XXXX via powershell
#The following will work with the Compliance Center in Exchange to search through all mailboxes and delete a specific email as long as it matches the tags
New-ComplianceSearch `
-Name Test9 `
-ExchangeLocation All `
-ContentMatchQuery 'subject:"INTRODUCING: A new way to consult Cisco experts" AND sent:08/01/2022'
#It should run and you should see the name of the job and that it has NotStarted
Start-ComplianceSearch -Identity Test9
#Just keep entering this next command until you see the status as completed
$GetResults = Get-ComplianceSearch -Identity Test9
Get-ComplianceSearch -Identity Test9
if (Get-ComplianceSearch | Where-Object {$GetResults_.Status -eq "InProgress";})
{
Get-ComplianceSearch -Identity Test9
}
else
{
New-ComplianceSearchAction -SearchName Test9 -Purge
}
exit
So you see the part where it says "#Just Keep entering this next command until you see the status as completed" is the part that I am trying to automate. Normally without scripting you would just keep running the Get-ComplianceSearch - Identity xxxx until you see completed then run the New-ComplianceSearchAction to purge the emails, but in the code posted above I have been trying to thow in an if loop statement to have it continually run that until the status is completed.
I want to run this powershell script with admin privileges so it won't give me the error:
Script Output with error
Here is the script:
$processes = "PDStyleAgent", "AdobeIPCBroker", "CCXProcess", "RichVideo64", "CCLibrary", "AdobeNotificationClient", "AdobeUpdateService", "PDHanumanSvr", "PDR"
Foreach ($process in $processes){
try {
$f = Get-Process $process -ErrorAction Stop
$f | kill
Write-Output "$process killed."
}
catch [Microsoft.PowerShell.Commands.ProcessCommandException]{
Write-Output "No instances of $process running."
}
}
Start-Sleep -Seconds 3
I want to run this script so it kill the processes that are giving errors
Some way to run PowerShell with admin privileges:
Search Powershell from the Windows search icon OR click the Windows button from the keyboard --> write Powershell --> You will see the Windows PowerShell --> Right-click on Powershell then click Run as administrator.
Run this command of a PowerShell console: Start-Process powershell -Verb runAs
Run your script from PowerShell like this: PowerShell -f C:\ScriptPath
For more details, you can check this StackOverflow question and answer.
I'm not sure what exactly you are asking about. If you want to start a script as administrator, you need to open PowerShell window "As administrator".
BTW, the script itself can be simplified without losing functionality:
$processes = "PDStyleAgent", "AdobeIPCBroker", "CCXProcess", "RichVideo64", "CCLibrary", "AdobeNotificationClient", "AdobeUpdateService", "PDHanumanSvr", "PDR"
Get-Process -Name $processes -ErrorAction SilentlyContinue | Stop-Process -Verbose
1.Create a shortcut to your Powershell script on your desktop
2.Right-click the shortcut and click Properties
3.Click the Shortcut tab
4.Click Advanced
5.Select Run as Administrator
NOTE: add powershell -f in front of the script path
Does anyone know if there is a way to have the output of an executed job be a clickable link?
I have a script that gets a link for a virtual environment in vCenter via powercli and I wanted to simplify the process in which the user got the vmdk console brought up. They currently have to select->copy->paste to search bar for it to work.
Here is my script:
Echo "Your Virtual Machine is now created and is being retrieved now."
$vcenter_password= "#option.vcenter_password#"
$Template_Name= "#option.Template_Name#"
if(-not (Get-Module -Name VMware.PowerCLI -ListAvailable)){
Install-Module -Name VMware.PowerCLI -AllowClobber -Force -Confirm:$false
}
Connect-VIServer -Server {{vcenter}} -User Administrator#DEPLOY.COMMS -Password $vcenter_password -Force
Get-VM $Template_Name | Select-Object #{N="IP Address";E={#($_.guest.IPAddress[0])}}
Echo "Your VM is available at the following URL for the next 30 seconds:"
Open-VMConsoleWindow -VM "$Template_Name" -urlonly
If your app supports HTML links like appname://, you can generate an HTML anchor element output in your Rundeck job. Take a look at this.
I have script which write some COMMAND to another script and start them in new window with Start-Job command (I really need that). $cred is credential of local administrator. Main script started from powershell windows which opened "run as administrator" (as machine administrator). COMMAND need to open with machine administrator account (like new window open with "run as administrator"). BUT new window open only with local administrator rights. I search in the internet for information to round this issue, but failed. May be someone know how i can run new window with start-job command with machine administrator ("run as administrator")?
$ScriptFile = "$env:TEMP\ScriptBlock.ps1"
Write-Output "`$ProfileApp = <COMMAND> | Out-File $ScriptFile -Width 300
$PJob = Start-Job -Name PJob -Credential $cred -FilePath $ScriptFile -Verbose -InitializationScript {Add-PsSnapin Microsoft.SharePoint.PowerShell} | Wait-Job
Receive-Job -Name PJob -Verbose
Remove-Job -Name PJob -ErrorAction SilentlyContinue -ErrorVariable err
Remove-Item -Path "$env:TEMP\ScriptBlock.ps1"
I believe this might be what you are looking for:
A self elevating PowerShell script