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
Related
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"}
I'm trying to autofit columns in sheet1 using following code.
$Userlijst | Export-Excel $ExportUsersXLS -autofilter #-WorksheetName "Sheet1"
$excel = $exportusersxls
write-host "xlsx : " $excel
$sheet = $excel.Workbook.Worksheets['Sheet1']
write-host "Sheetname : " $sheet
foreach ($c in 1..9) {Set-ExcelRange -Address $sheet.Column($c) -AutoFit }
Export-Excel -ExcelPackage $excel
The output errors :
xlsx : c:\scripts\DepartmentUsers.xlsx
Cannot index into a null array.
At C:\scripts\Get-Departments-Users.ps1:46 char:1
$sheet = $excel.Workbook.Worksheets['Sheet1']
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Sheetname :
You cannot call a method on a null-valued expression.
At C:\scripts\Get-Departments-Users.ps1:48 char:23
... h ($c in 1..9) {Set-ExcelRange -Address $sheet.Column($c) -AutoFit }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
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
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.
Good day everyone.
I am a starting programmer in powershell and am trying to make a program input help desk calls into an excel sheet to import into the help desk ticketing system.
My script:
$excel_file_path = 'G:\IT\Helpdesk\Daily Calls.xlsx'
## Instantiate the COM object
$Excel = New-Object -ComObject Excel.Application
$ExcelWorkBook = $Excel.Workbooks.Open($excel_file_path)
$ExcelWorkSheet = $Excel.WorkSheets.item("sheet1")
$ExcelWorkSheet.activate()
## Find the first row where the first 7 columns are empty
$row = ($ExcelWorkSheet.UsedRange.Rows | ? { ($_.Value2 | ? {$_ -eq $null}).Count -eq 7 } | select -first 1)
$test = "this is a test"
$ExcelWorkSheet.Cells.Item($row,1) = $test
$ExcelWorkBook.Save()
$ExcelWorkBook.Close()
$Excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)
Now, I did take this from another page online and modified it to what I need, but it is giving me this error;
Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
At H:\Scripts\Call_Log.ps1:12 char:1
+ $ExcelWorkSheet.Cells.Item($row,1)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
OR
Exception from HRESULT: 0x800A03EC
At H:\Scripts\Call_Log.ps1:11 char:1
+ $ExcelWorkSheet.Cells.Item($row,1) = $test
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
I don't understand what is going on or what is mismatched. Could anyone please help?