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

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

Related

Copy account creation date time value to an extension attribute in Active Directory

I'm trying to create a PowerShell script that copies an AD user account's creation date and time value to the extension attribute 2 field in the user's account. Here's the contents of my script:
$users = get-aduser -Filter * -Properties * -SearchBase "DC=TestDC1" | Where-Object {$_.whenCreated -ne $null }| Select-Object Samaccountname,whenCreated
foreach($user in $users)
{
set-aduser -identity $user.Samaccountname -add #{extensionAttribute2=$user.whenCreated}
}
When I run the script, it fails with the following error:
set-aduser : Invalid type 'System.DateTime'.
Parameter name: extensionAttribute2
At C:\Users\admin\Documents\PowerShell\Scripts\Update_User_AccountCreation_Attribute.ps1:7 char:1
+ set-aduser -identity $user.Samaccountname -add #{extensionAttribute2= ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (john.sp.smith:ADUser) [Set-ADUser], ArgumentException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Comm
ands.SetADUser
I believe this is because extension attributes in AD only accept text-based values by default. How can I update the script to convert the account creation date and time value to a string that I can copy to extension attribute 2?
You just need to convert the DateTime to a string. You can do that with .ToString().
set-aduser -identity $user.Samaccountname -add #{extensionAttribute2=$user.whenCreated.ToString()}
If you want to use a specific date format, you can read the documentation for ToString().

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"}

I can't delete azure alert

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.

Variable concatenation in wrong order

I have the following:
function createFolder($folderName, $curPath)
{
$dest = $curPath + $folderName
write-host "Path is : " + $dest
# code to mess around with files etc
}
When I run this it gives me the following output:
Path is : + Test_Folder C:\Users\Me
Is there something I'm missing with the + operator, or a join/concat method that is meant for this kind of function? What is the correct way to create/concat/manipulate paths in PowerShell (I've just started using this to automate some cleanup tasks on my desktop).
EDIT: In case it makes a difference, this is what I see when I run the version command:
PS C:\Users\Me> version
BladeLogic Network Shell 8.2.01.273 (Release) [May 12 2012 21:56:02]
Copyright (C) 1996-2012 BladeLogic Inc.
Also, I'm on a work computer with no administrative privileges.
I tried:
$currentPath = "C:\Users\n0223270\Downloads"
$test = "test"
createFolder($test, $currentPath)
function createFolder($folderName, $curPath)
{
$dest = join-path -path $curPath -childpath $folderName
Write-Host $dest
}
This was the following error:
Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At line:4 char:28
+ $dest = join-path -path <<<< $curPath -childpath $folderName
+ CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
createFolder($test, $currentPath)
This isn't how you call a Powershell function. This is passing the first parameter as an array of two strings. The second parameter would be null because it's not specified and there's no default.
Try:
createFolder $test $currentPath

DateTime variable not parsing correctly, string works

I'm trying to pass a variable into a powershell command like so:
$Today = Get-Date
Get-SCSMClassInstance -Filter {ClosedDate -eq $Today}
But I get this error:
Get-SCSMClassInstance : ClosedDate_C529833E_0926_F082_C185_294CBC8BB9FD='$Today'
-- String was not recognized as a valid DateTime.
At line:1 char:1
+ Get-SCSMClassInstance -ComputerName $computer $IncidentClass -Filter
{ClosedDate ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Syste...InstanceComman
d:GetSCClassInstanceCommand) [Get-SCClassInstance], UnknownDatabaseException
+ FullyQualifiedErrorId : ExecutionError,Microsoft.SystemCenter.Core.Commands
.GetSCClassInstanceCommand
If I pass the string directly, it works fine, regardless of format:
Get-SCSMClassInstance -Filter {ClosedDate -eq "Friday, June 5, 2015 11:42:33 AM"}
Get-SCSMClassInstance -Filter {ClosedDate -gt "2015-6-5 11:42:33Z"}
I've tried setting the variable as DateTime as well as a string, every imaginable format - I've ensured that, when the variable is parsed, it will absolutely turn into the correct string, but nothing works.
Any ideas?
The Filter parameter is a string not scriptblock. It is working with a scriptblock in those other cases because the string form of script block is the text of the block without the surrounding braces. However, in this case, you need the variable to be substituted in the filter. Try this:
Get-SCSMClassInstance -Filter "ClosedDate -eq ""$Today"""

Resources