I am writing a script where a part of it needs to connect to domain controller and get all the gpo's currently linked to a specific OU.
the line that does that is:
Invoke-Command -Session $S -ScriptBlock {Get-GPInheritance -target $using:Switch -domain shahar.local -server dc01 }
$s= credentials, $switch is a a variable that contains an ou that was picked.
those variables exists and they are good.
the error i get is:
Value does not fall within the expected range.
+ CategoryInfo : NotSpecified: (:) [Get-GPInheritance], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.GroupPolicy.Commands.GetGPInheritanceCommand
+ PSComputerName : DC01
can anyone please assist?
I'm posting this as answer, because IMO there are too many questions that remain 'unanswered' while the solution is given in a comment.
The error message triggered me to check if any of the variables you use perhaps is an Automatic variable and in this case it is the variable $switch.
Using a different self-defined variable name here like $selectedOU should solve the problem.
Related
Afternoon everyone. I'm running into an issue I'm not sure how to handle. I'm working on a script for work to deploy a Domain Controller using PSremoting. It all works well in fine until I get to where I'm importing some GPOs from backups.
*All the commands are run under invoke-command
I run the command Import-GPO -BackUpName $GPO -TargetName $GPO -Path $GPOPath -MigrationTable $MigTable -CreateIfNeeded
When I run this, I get an error on the host:
Operation is not valid due to the current state of the object.
+ CategoryInfo : NotSpecified: (:) [Import-GPO], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.GroupPolicy.Commands.ImportGpoCommand
+ PSComputerName : v204-DC1
I can't seem to find anything that says what this means. When I check for the GPOs on the DC, they all show up and seem to be linked properly. I am curious what this error is, or if I should just append -ErrorAction SilentlyContinue to the end of my code.
Ended up being an issue with my migration table. I rolled back to an earlier one and ended up being good to go
I have a PowerShell script which checks the currently signed in user as part of its start-up process. I'm using .Net to do this by adding the assembly:
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$cUser = [System.DirectoryServices.AccountManagement.UserPrincipal]::Current
For almost everyone this works fine and I get a UserPrincipal object that I can use elsewhere, however there are a couple of users who get the following error when running it:
Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'. At line:2 char:1
+ [System.DirectoryServices.AccountManagement.UserPrincipal]::Current
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], InvalidCastException
+ FullyQualifiedErrorId : System.InvalidCastException
This is on a standard Windows 10 20H2 install and doesn't matter if PowerShell is running elevated or not. I've never seen this call return anything other than a UserPrincipal before, so I would be grateful for any advice: is this something I can deal with in code, or is there some underlying issue with the machines that are returning this exception?
I don't know if this is what you're looking for:
$cUser = Get-ADUser $Env:Username -Properties *
This has the most important attributes that you can use for whatever you want later on. It provides as much attribute as the code you posted that didn't work for some of the user.
Afternoon!
I have run into an issue with PowerShell DSC (the Start-DscConfiguration cmdlet specifically) 2 days trying to figure it out, now I am here :)
I am getting the following error for a specific MOF file, prior MOFs run fine.
The data source could not process the filter. The filter might be missing or it might be invalid. Change the filter
and try the request again.
+ CategoryInfo : InvalidArgument: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : HRESULT 0x8033801a
EDIT: Has anyone experienced this error before? I can share the MOF file in question, with some restricted info removed.
Thank you
The issue here wasn't with PowerShell DSC, rather just PowerShell in itself.
I had a cmdlet within a switch block. As an example:
Switch($item){
{$_ -eq $true}{do something}
{$_ -eq $fales}{do something}
get-service -name $item
}
It was the get-service cmdlet that could not be filtered.
In my test script by powershell, I'd start an Edge browser and get it's main process's ID. Simply like this:
$edge = Start-Process microsoft-edge: www.ted.com -PassThru
but instead of able to get the process id from $edge.Id, I've got error message like this:
Start-Process : This command cannot be run completely because the system cannot find all the information required.
At line:1 char:7
+ $edge=Start-Process microsoft-edge: www.ted.com -PassThru
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Is there any simple and straightforward way to really doing this without enumerate and check the process list?
Thanks!
I try to test your script and I am getting a similar error as yours.
Based on my search result, passthru is not one of the common parameters, and it does not exist everywhere.
Reference:
Use the PowerShell Passthru Parameter and Get Back Objects
I think it is not available for the MS Edge browser and that's why the script gives an error.
I try to search for an alternative command for PassThru but I did not get any helpful information about it.
In this situation, it is better to enumerate and check the process list
I am using PowerShell for managing my Office365 account. When I try to set parameters for existing mailbox, PowerShell ISE raises error. When I specify "RetentionComment", "LitigationHoldEnabled", "RetentionUrl" or "MaxSendSize" as Set-Mailbox function the following error occurs:
A positional parameter cannot be found that accepts argument '-maxsendsize'.
+ CategoryInfo : InvalidArgument: (:) [Set-Mailbox], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Set-Mailbox`
These parameters documented in TechNet documentation library at
http://technet.microsoft.com/en-en/library/bb123981(v=exchg.150).aspx
For example I use the following commands with parameters:
Set-Mailbox -Identity "my.mailbox" -MaxSendSize 12345
Set-Mailbox "my.mailbox" -RetentionComment "Hello World!"
Set-Mailbox -Identity "my.mailbox" -LitigationHoldEnabled:$False
Any idea? Please help!
The MaxSendSize is only supported in Exchange 2013 or Exchange Online 2013. If your tenant has not been upgraded yet to wave 15 (the 2013 suite) you will not be able to use this command. Also, if you have ADFS set up you may also be unable to run this command because it must be set in AD and not in Exchange. Hope this helps.
For the -MaxSendSize 12345BI think you have to add a unit to the end so -MaxSendSize 12345B the available units are B/MB/GB/TB.
For -RetentionComment this comment can only be set if the RetentionHoldEnabled parameter is set to $true. So check that first.
For -LitigationHoldEnabled you don't need that : in there so -LitigationHoldEnabled $false