How to resolve convertfrom-stringdata error with name=value - powershell

command is ((Get-WindowsFeature | Format-List|out-string).Trim().replace(':', '=').replace('', '\') -split '(\r?\n){2,}') and
Is there a way to put all multi-lines into a single for selected Name's like only to "Description"
Name = AD-Certificate
DisplayName = Active Directory Certificate Services
Description = Active Directory Certificate Services (AD CS) is used to create certification authorities and related role services that allow you
to issue and manage certificates used in a variety of applications.
Installed = False
Error:
PS C:\Users\Administrator> ((Get-WindowsFeature | Format-List|out-string).Trim().replace(':', '=').replace('\', '\\') -split '(\r?\n){2,}') |where-object {![string]::IsNullOrWhiteSpace($_)}|convertfrom-stringdata|convertto-json
convertfrom-stringdata : Data line ' to issue and manage certificates used in a variety of applications.' is not in **'name=value'**
format.
At line:1 char:165
+ ... ct {![string]::IsNullOrWhiteSpace($_)}|convertfrom-stringdata|convert ...
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [ConvertFrom-StringData], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand

Related

Update multiple users

I am trying to simultaneously update some users in my AD, but not being able to generate the script correctly. I am working with .csv and I get errors!
script
Import-Csv -Path C:\Temp\userteste3.csv | foreach-Object {Set-ADUser -Identity $_.SamAccountName -Add #{-telephoneNumber $_.telephoneNumber;-OtherPhone $_.OtherPhone;ipPhone $_.ipPhone}}
csv
error
No linha:1 caractere:105
+ ... oreach-Object {Set-ADUser -Identity $_.SamAccountName -Add #{-telepho ...
+ ~
O literal de hash estava incompleto.
No linha:1 caractere:186
+ ... ber $_.telephoneNumber;-OtherPhone $_.OtherPhone;ipPhone $_.ipPhone}}
+ ~
Token '}' inesperado na expressão ou instrução.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : IncompleteHashLiteral

How to check particular VMware VM is not currently running in the task using PowerShell?

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.

Bulk Add SmtpAddress to users Exchange 2010

We just recently added a domain to our accepted domains and e-mail address policy. While many of our users follow that policy, we have a third domain that some users have as their primary address that does not follow an address policy. I need to take those users and add an SMTP Address in the format of firstname.lastname#domain2.com.
E.g., john.doe#domain3.com (primary) has john.doe#domain1.com as an alias and needs to have john.doe#domain2.com added as an SMTP Address.
I have the following code but am receiving errors:
$Users = Get-Mailbox -ResultSize Unlimited | Where-Object {($_.PrimarySMTPAddress -like "*domain3.com*)}
foreach ($a in $Users) {
$b = Get-User $a.Primary.SMTPAddress
$a.EmailAddresses.Add("$($b.Firstname + "." + $b.Lastname)#domain2.com")
}
$Users |%{Set-Mailbox $_.PrimarySMTPAddress -EmailAddresses $_.EmailAddresses
Errors are as follows:
Cannot process argument transformation on parameter 'Identity'. Cannot convert the "john.doe#domain3.com" value of type "Microsoft.Exchange.Data.SmtpAddress" to type "Microsoft.Exchange.Configuration.Tasks.UserIdParameter".
+ CategoryInfo : InvalidData: (:) [Get-User], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-User
Exception calling "Add" with "1" argument(s): "The address '.#domain2.com' is invalid: ".#domain2.com" isn't a valid SMTP address. The domain name can't contain spaces and it has to have a prefix and a suffix, such as example.com."
At C:\_scripts\SmtpAdd.ps1:4 char:23
+ $a.emailaddresses.Add <<<< ("$($b.Firstname + "." + $b.LastName)#domain2.com")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Cannot process argument transformation on parameter 'Identity'. Cannot convert the "john.due#domain3.com" value of type "Microsoft.Exchange.Data.SmtpAddress" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter".
+ CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox
Thanks
I think the problem starts with this line:
$b = Get-User $a.Primary.SMTPAddress
Get-User fails to return a valid user as $a.Primary.SMTPAddress doesn't return a type that Get-User can use. That then causes EmailAddresses.Add to fail as $b is null. Set-Mailbox fails for the same reason as Get-User
Try this instead (you'll also need to do this on the Set-Mailbox line):
$b = Get-User $a.Primary.SMTPAddress.ToString()

Trying to Create a script that will get my filtered list of Get-Adcomputer then run a command on each

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

PowerShell remote event log parsing

I wrote a small script to grab event log entries from a remote machine and write it to a .csv file. The script works when targeting a single machine, but when I try to implement a for loop and loop it over all machines in Active Directory, I get this error:
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADComputer]
does not contain a method named 'op_Addition'.
At Y:\srp.ps1:7 char:143
+ ... | Export-Csv $($computer + ".csv")
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Export-Csv : Cannot validate argument on parameter 'Path'. The argument is null or empty.
Provide an argument that is not null or empty, and then try the command again.
At Y:\srp.ps1:7 char:141
+ ... 0 | Export-Csv $($computer + ".csv")
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Export-Csv],
ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,
Microsoft.PowerShell.Commands.ExportCsvCommand
The error indicates there's a problem with the Export-Csv command, but running the command by itself creates the log files needed. Here is the full script, for reference:
# Gets SRP event log entries from remote machine and writes them to a .csv file
# of the same name.
Write-Output "Running..."
$computers = Get-ADComputer -filter {(Name -like "PC*") -or (Name -like "LT*")}
foreach ($computer in $computers) {
Get-EventLog -LogName Application -Source Microsoft-Windows-SoftwareRestrictionPolicies
-ComputerName $computer -Newest 10 | Export-Csv $($computer + ".csv")
} #end foreach
Write-Host "Done."
Any ideas as to why this error appears when I try to loop over computers in AD?
It looks like Get-ADComputer returns ADComputer objects, but you're passing it to Get-EventLog's ComputerName parameter, which takes a string, as-is. I'm assuming you'll need to grab the name property from the Microsoft.ActiveDirectory.Management.ADComputer object.