I can't delete azure alert - azure

i have the following alert in Azure:
PS C:\> Get-AzResource -Name "alert for rg"
Name : alert for rg ResourceGroupName : plaz-rg2 ResourceType : Microsoft.AlertsManagement/actionRules Location : global ResourceId : /subscriptions/XXXX/resourceGroups/plaz-rg2/providers/Microsoft.Alerts
Management/actionRules/alert for rg
I was deleting it before but it is still visible.
I can't delete resource group because of it.
PS C:\> Remove-AzResourceGroup -name "plaz-rg2"
Confirm
Are you sure you want to remove resource group 'plaz-rg2'
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
Remove-AzResourceGroup : Long running operation failed with status 'Conflict'.
At line:1 char:1
+ Remove-AzResourceGroup -name "plaz-rg2"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Remove-AzResourceGroup], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.RemoveAzureResourceGroupCmdlet
When I'm trying to delete the alert alone it is not possible
PS C:\> Remove-AzResource -Name "alert for rg" -ResourceType Microsoft.AlertsManagement/actionRules
Confirm
Are you sure you want to delete the following resource:
/subscriptions/XXXX/providers/Microsoft.AlertsManagement/actionRules/alert%20for%20rg
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y
Remove-AzResource : ResourceNotFound : The Resource 'Microsoft.AlertsManagement/actionRules/alert for rg' under resource gr
oup '<null>' was not found.
At line:1 char:1
+ Remove-AzResource -Name "alert for rg" -ResourceType Microsoft.Alerts ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Remove-AzResource], ErrorResponseMessageException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet
Any idea how to get rid of it?

I see this behavior if we are not passing the ResourceGroupName as input parameter along with Remove-AzResource.
However if you pass in the ResourceGroupName it runs successfully. Please try this out.
Additional documentation reference to remove AlertRule.
Hope this helps.

Related

what positional parameter should I be looking for when trying to delete java version 1.8.0_321

PS C:\Users\family> remove-item C:\Users\family> java -version "1.8.0_321"
Remove-Item : A positional parameter cannot be found that accepts argument 'java'.
At line:1 char:1
+ remove-item C:\Users\family> java -version "1.8.0_321"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-Item], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

Is there a way to find a Removed Keyvault by it's tags

I need to find the KeyVaultname of my removed keyvault (by softdelete) by its specifics tags.
This is the keyvault I need to find:
KeyVault In Removed State
Unfortunately the command to find the tags for a keyvault by below cmd doesn't work for a Keyvault which is in a Removed state. (It works when the KeyVault is not removed)
(Get-AzKeyvault -InRemovedState -tag #{"RemovalDate" = "14-04-2022"})
Gives the following error:
Get-AzKeyVault : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:2
+ (Get-AzKeyvault -InRemovedState -tag #{"RemovalDate" = "14-04-2022"})
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-AzKeyVault], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.Azure.Commands.KeyVault.GetAzureKeyVault
I tried as well:
(Get-AzKeyvault -InRemovedState | Where-Object {$_.Tag["RemovalDate"] -eq "14-04-2022"})
Which gives the following error:
Cannot index into a null array.
At line:1 char:49
+ ... RemovedState | Where-Object {$_.Tag['RemovalDate'] -eq '14-04-2022'})
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Thank you very much for your help!
You were close, just needed to pipe results of the Get-AzKeyVault, then query it like any other object.
First, find out the object types that are returned.
Get-AzKeyVault -InRemovedState | get-member
This displays the column names and object type. Now write your query appropriately.
Get-AzKeyVault -InRemovedState |
select VaultName, Tags |
where {$_.Tags["RemovalDate"] -eq "14-04-2022"}

Wild cards in azure cli script

How can use wildcards in azure cli?
I have the following that i want to have in my azure cli script:
$(System.DefaultWorkingDirectory)/**/*.zip
As it is now, I have the following path in my azure cli:
$artifactfolder = '$(System.DefaultWorkingDirectory)' + '\_TestApi\drop\TestApi.zip'
So how can I use the approach with the wild card insstead?
Here is my CLI script:
$resourceGroup = "Test"
$appServicePlan = "brajzoreappserviceplan"
$appServiceName = "brajzoreappservice2"
$artifactFolder = Get-ChildItem -Path "$(System.DefaultWorkingDirectory)" + "\**\*.zip"
az webapp deployment source config-zip --resource-group $resourceGroup --name $appServiceName --src $artifactfolder
I get the following error when I run the script:
2021-03-12T07:47:10.5624737Z Get-ChildItem : A positional parameter cannot be found that accepts argument '\**\*.zip'.
2021-03-12T07:47:10.5627860Z At D:\a\_temp\azureclitaskscript1615535200528_inlinescript.ps1:9 char:19
2021-03-12T07:47:10.5629171Z + $artifactFolder = Get-ChildItem -Path "D:\a\r1\a" + "\**\*.zip"
2021-03-12T07:47:10.5630150Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-03-12T07:47:10.5630966Z + CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParentContainsErrorRecordException
2021-03-12T07:47:10.5632192Z + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
2021-03-12T07:47:10.5633181Z
2021-03-12T07:47:10.6016965Z ##[error]Script failed with exit code: 1
As the error shows it's not an acceptable argument '***.zip'. And according to the description here for the command Get-ChildItem, it should be like this:
$artifactFolder = Get-ChildItem -Path "$(System.DefaultWorkingDirectory)\*\*\*.zip"

Powershell script works in ISE / Console but not Task Scheduler

I currently have a script that allows me to convert any excel spreadsheets within a specific folder to PDF documents which are saved in another folder. The script works great if you run it from Powershell ISE / Console. However, if you run the script by creating a task within Windows Task Scheduler it fails.
ZAOCC.ps1
Start-Transcript -Path 'C:\Temp\Log.txt'
Install-Module -Name ImportExcel -Force
$path = 'C:\Temp\Excel'
$path2 = 'C:\Temp\PDF'
$xlFixedFormat = 'Microsoft.Office.Interop.Excel.xlFixedFormatType' -as [type]
$excelFiles = Get-ChildItem -Path $path -include *.xls, *.xlsx -recurse
$objExcel = New-Object -ComObject excel.application
$objExcel.visible = $false
$date = Get-Date -Format 'dd.MM.yyyy'
foreach($wb in $excelFiles)
{
$filepath = Join-Path -Path $path2 -ChildPath ('Mine Control Record - ' + $date + '.pdf')
$workbook = $objExcel.workbooks.open($wb.fullname, 3)
$workbook.Saved = $true
"Saving $filepath"
$workbook.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $filepath)
$objExcel.Workbooks.close()
}
$objExcel.Quit()
I have included Start-Transcript and found the following errors when running the script through task scheduler:
Microsoft Excel cannot access the file 'C:\Temp\Excel\Test.xlsx'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
At C:\Temp\ZAOCC.ps1:16 char:5
+ $workbook = $objExcel.workbooks.open($wb.fullname, 3)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
Microsoft Excel cannot access the file 'C:\Temp\Excel\Test.xlsx'. There are several possible
reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
At C:\Temp\ZAOCC.ps1:16 char:5
+ $workbook = $objExcel.workbooks.open($wb.fullname, 3)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
The property 'Saved' cannot be found on this object. Verify that the property exists and can be set.
At C:\Temp\ZAOCC.ps1:17 char:5
+ $workbook.Saved = $true
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
The property 'Saved' cannot be found on this object. Verify that the property exists and can be
set.
At C:\Temp\ZAOCC.ps1:17 char:5
+ $workbook.Saved = $true
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Saving C:\Temp\PDF\Mine Control Record - 10.07.2020.pdf
You cannot call a method on a null-valued expression.
At C:\Temp\ZAOCC.ps1:19 char:5
+ $workbook.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $filepat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Temp\ZAOCC.ps1:19 char:5
+ $workbook.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $filepat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
PS>$global:?
True
My task within Task Scheduler is set to run with admin privileges with the following settings:
Program/Script powershell.exe
Add arguments(optional) -ExecutionPolicy Bypass C:\Temp\ZAOCC.ps1
Any help would be appreciated!
Solution turned out to be an excel bug. Followed the solution here: Powershell script cannot access a file when run as a Scheduled Task

Can't call up SpFeature by Display Name - sharepoint 2010 power shell

I am running the sharepoint 2010 Management Shell and I am did this
Get-SPFeature –DocumentRoutingResources –Site http://sp2010 |ft -auto
Get-SPFeature : A parameter cannot be
found that matches parameter name
'Docume ntRoutingResources'. At line:1
char:40
+ Get-SPFeature -DocumentRoutingResources <<<< -Site http://sp2010 |ft -auto
+ CategoryInfo : InvalidArgument: (:) [Get-SPFeature],
ParameterB indingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.SharePoint.Powe
rShell.SPCmdletGetFeature
I am not sure why I get that since when I just do
Get-SPFeature –Site http://sp2010
It shows up
The code you entered is passing a parameter called DocumentRoutingResources to the PowerShell command, which doesn't have such a parameter.
If you want just that item returned, you can filter for it quite easily:
Get-SPFeature -site http://tskm | ? {$_.DisplayName -eq "DocumentRoutingResources" }
The "?" is a shortcut for the cmdlet "where-object".
For your specific example, the cmdlet supports the 'identity' parameter as shown here:
Get-SPFeature -identity DocumentRoutingResources -Site http://sp2010

Resources