Needed to clean up a winmail.dat issue by adding a contact and setting a couple of parameters. All worked as shown, except the command to test that it worked.
Get-MailContact | Select randomemail#email.com | Select -UseMapiRichTextFormat
What is the reason for this failure?
Select-Object : A parameter cannot be found that matches parameter
name 'UseMapiRichTextFormat'. At line:1 char:62 + ... t 1 Select
support#solidpe.maxdesk.us 1 Select -UseMapiRichTextFormat +
---------------------- + CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterBindingException + FullyQualifiedErrorId :
NamedParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand
I think what you actually need is this:
Get-MailContact |
Where-Object {$_.ExternalEmailAddress -eq 'randomemail#email.com'} |
Select-Object -Property UseMapiRichTextFormat
Where-Object limits the result set by comparing each contact's ExternalEmailAddress property and only including the objects that match in the output (which should only be one)
Select-Object limits the output object members to a subset of the original members
Related
The code:
$Bios = Get-WmiObject -class Win32_BIOS | Select-Object -Property PSComputerName,Manufacturer,BIOSVersion | ConvertTo-EnhancedHTMLFragment -As List
$Bios2 = Get-WmiObject -class Win32_BIOS | Select-Object -Property PSComputerName,Manufacturer,BIOSVersion | ConvertTo-EnhancedHTMLFragment -As Table
ConvertTo-EnhancedHTML -HTMLFragments $Bios,$Bios2 | Out-File AsExample.html
The error:
ConvertTo-EnhancedHTML : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ ConvertTo-EnhancedHTML -HTMLFragments $Bios,$Bios2 | Out-File AsExamp ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [ConvertTo-EnhancedHTML], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,ConvertTo-EnhancedHTML
I don't understand why I am receiving the error. I've examined the help, and what I'm doing seems like it ought to be fair game:
-HTMLFragments <String[]>
One or more HTML fragments, as produced by ConvertTo-EnhancedHTMLFragment.
-HTMLFragments $part1,$part2,$part3
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
I have resolved the error by specifying an additional parameter:
ConvertTo-EnhancedHTML -HTMLFragments $Bios,$Bios2 -CSSStyleSheet syles.css | Out-File AsExample.html
While reviewing the 2 available parameter sets for ConvertTo-EnhancedHTML, I noticed that there was only 1 parameter required in each one -- -HTMLFragments. The error was telling me it didn't know which parameter set I wanted to use. So what I ended up having to do was specify the -CSSStylesheet parameter, as that parameter and its opposing -CSSUri parameter are the only parameters unique to their respective sets. In other words, the command wouldn't execute because I had to specify one of the CSS parameters so powershell knew which parameter set to use DESPITE THE FACT THAT neither of the CSS parameters are actually required parameters. Wow!
I have a super simple script that I swear I use almost every day, but for some unknown reason my $_. variable is null.
Could someone please spot check it? there is only one column in the CSV I am importing, however it has no header so i don't know if that is what is causing it.
$results = import-csv C:\####\####\####\finddestinguishednamesof.csv | foreach-object {
Get-ADGroup $_. -Properties SamAccountName,DistinguishedName
}
$results | select SamAccountName,DistinguishedName |
Export-Csv C:\Users\laruemi\Desktop\test.csv -NoTypeInformation
I keep getting this error and do not know why.
Get-ADGroup : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At C:\Users\laruemi\Desktop\getdestinguishedname.ps1:2 char:13
+ Get-ADGroup $_. -Properties SamAccountName,DistinguishedName
+ ~~
+ CategoryInfo : InvalidData: (:) [Get-ADGroup], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADGroup
The list of CSV's I am importing is just a list of SAMAccountNames with no header. i dont think that should cause this error, but it might. Can someone please give me a sanity check?
I'm trying to create a Powershell script that prints out only certain AD groups from the Folder Permission settings. However for some reason Powershell doesn't recognize StartsWith function.
("C:\folder" | get-acl).Access | ForEach-Object { if (($_.IdentityReference).StartsWith("sl_test")) { continue }; $_ }
When I run this I got errors similar to this for every foreach object:
Method invocation failed because [System.Security.Principal.NTAccount] does not contain a method named 'StartsWith'.
At C:\temp\test.ps1:1 char:56
+ ("C:\folder" | get-acl).Access | ForEach-Object { if (($_.IdentityReference).St ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Any suggestions on how to get this to work?
IdentityReference is a [System.Security.Principal.NTAccount]according to your error message.
But .StartWith is a method on the String type. If you call a method, Powershell does no magic for you, AFAIK.
Try ... ($_.IdentityReference) -match "^sl_test" ..., which should do the implicit string conversion.
If you want the string representation of an IdentityReference (regardless of whether it's and NTAccount object or a SID), you can reference the Value property:
$_.IdentityReference.Value.StartsWith('sl_test')
Try:
Get-Acl -Path "C:\folder" | Select-Object -ExpandProperty Access | Where-Object {$_.IdentityReference -like "sl_test*" }
You can customize the output with an additional | Select-Object -Property XY
I need to check particular VMware VM is currently in the recent task like CLone_task, Migrate_VMTask,.etc and also skip that VM before VM migration starts..
I have tried the below code:
PS> Get-Task (Get-VM -Name VM1) | Select State
Get-Task : Cannot bind parameter 'Status'. Cannot convert the "nalb00cava3"
value of type "VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl"
to type "VMware.VimAutomation.Sdk.Types.V1.TaskState".
At line:1 char:10
+ Get-Task (Get-VM -Name nalb00cava3) | Select State
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Task], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetTask
This should do what you're looking for, the final pipe is where you would define the specific VM.
Get-Task | ?{$_.ObjectId -match 'VirtualMachine'} | Select #{N='VM';E={(Get-View -Id $_.ObjectId).Name }},State,Description | where {$_.VM -eq "VM1"}
It filters on ObjectId from Get-Task, then referencing the Id, determines the VM names, and finally filters on the VM you define.
Firstly,
I am very new to powershell. Everytime I think i get the logic i go WTF.. If this was bash it would be so easy etc..
what am I trying to do exactly ...
Get all computers from AD that Meet the Xiopwb* criteria. Once i have the list I need to change the permissions on the \\Xiopwb20\Nsiwebroot Directory to ONLY INCLUDE Domain Administrators and A Security group "webadmins"
My Logic:
Get all computers from AD that meet Xio*PWB*
Take just the NAME of objects in that list
for ever "name" in that list do Get-ACL \\Name from list\Nsiwebroot
remove *
add user / group.
What I have:
PS C:\Windows\system32> Get-ADComputer -filter * | Where-Object {$_.Name -like "xiopwb*"} | Select Name | ForEach-Object { Get-Acl \\$_.Name\nsiwebroot}
all up to the "ForEach" works... I get just the names of the PC's that I need etc..
Simple as possible I don't need a 100 line script.
Thanks
** update **
it is double \ its just not showing it... no idea why
Looks like it is doing what I want to a degree. However its spitting out the format funky. #{Name=XIOPWB09}
PS C:\Windows\system32> Get-ADComputer -filter * | Where-Object {$_.Name -like "xiopwb*"} | Select Name | ForEach-Object {get-acl "\\$_\D$\nsiwebroot"}
get-acl : Cannot find path '\#{Name=XIOPWB09}\D$\nsiwebroot' because it does not exist.
At line:1 char:99
+ ... opwb*"} | Select Name | ForEach-Object {get-acl "\$_\D$\nsiwebroot"}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Acl], ItemNotFoundException
+ FullyQualifiedErrorId : GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand
get-acl : Cannot find path '\#{Name=XIOPWB06}\D$\nsiwebroot' because it does not exist.
At line:1 char:99
+ ... opwb*"} | Select Name | ForEach-Object {get-acl "\$_\D$\nsiwebroot"}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Acl], ItemNotFoundException
+ FullyQualifiedErrorId : GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand
"Select Name" returns an Object with Table Header Name. "Select -ExpandProperty Name" is What needed here, which will convert it o String.
Regards,
kvprasoon