Get-PrintConfiguration doesnt seem to work - powershell

I am trying to use Get-PrintConfiguration on a networked printer but for some reason it returns this error
Get-PrintConfiguration : The specified printer was not found. At
line:1 char:1
+ Get-PrintConfiguration -PrinterName "Printer1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_PrinterConfiguration:ROOT/StandardCi...erConfiguration)
[Get-PrintConfiguration], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070709,Get-PrintConfiguration
Is there something I am missing? The Printer name is correct and im somewhat confident the syntax is correct.

Edit:
I just noticed the second line. If you're specifying a printer name by concatenating multiple strings, be sure to surround the concatenations with parenthese. Example:
Get-PrinterConfiguration -PrinterName ("Printer1" + "-PC1")
Hope some of this helps.
Original:
Only posting this as an answer since I don't have enough reputation to make a comment, but in order to get a proper answer, could you provide more details, please? Perhaps a code/script example?
This worked for me to get a network printer configuration
Get-Printer | Where-Object -Property 'Name' -EQ 'Sharp MX-4140N' | Get-PrintConfiguration
PrinterName ComputerName Collate Color DuplexingMode
----------- ------------ ------- ----- -------------
Sharp MX-4140N True True OneSided
Note: computer name blanked intentionally.

Related

Restoring SSRS / PowerBI Reporting Server encryption key using Powershell

I have the following Powershell code to restore an Encryption key on a Power BI Report Server instance:
$encKeyPath = "C:\Test\enc.snk"
$encKeyPass = Read-Host 'Enter password for key:' -AsSecureString
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion SQLServer2016
When I run this I get the error:
Get-WmiObject : Invalid namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v13\Admin"
At C:\Users\MyUser\Documents\WindowsPowerShell\Modules\ReportingServicesTools\ReportingServicesTools\Functions\Utilities\New-Rs
ConfigurationSettingObject.ps1:100 char:19
+ $wmiObjects = Get-WmiObject #getWmiObjectParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
I have tried also tried with the -ReportServerInstance and -ReportServerVersion parameters but get the same error message. I have also tried my local computer name for the -ComputerName parameter rather than localhost but still had no luck.
The error seems to refer to an error in the actual module itself rather than my code. Can anyone suggest where I am going wrong?
Environment
Power BI Report Server version: 1.8.7450.37410 (May 2020)
Instance name: PBIRS
Report Manager URL: http://localhost/reports
Service URL: http://localhost/reportserver
ReportServer database is on a SQL Server 2016 instance (the database name is PowerBIReportServer)
EDIT:
Using the two answers so far, I have found the following:
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion SQLServer2016
Throws
Invalid namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v13\Admin"
and changing the -ReportServerVersion:
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion SQLServer2017
Throws
Invalid namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v14\Admin"
(note the difference in versions)
running
Get-WmiObject -Namespace "Root/Microsoft/SqlServer/ReportServer/RS_PBIRS" -Class __Namespace | Select-Object -Property Name | Sort Name
outputs:
Name
----
V15
which makes sense as to why the two different -ReportServerVersion arguments throw an error.
this page suggests
+--------------------+---------+
| SQL Server Release | Version |
+--------------------+---------+
| SQL Server 2012 | 11 |
| SQL Server 2014 | 12 |
| SQL Server 2016 | 13 |
| SQL Server 2017 | 14 |
| SQL Server 2019 | 15 |
+--------------------+---------+
but changing -ReportServerVersion to SQLServer2019 returns:
Restore-RSEncryptionKey : Cannot process argument transformation on parameter 'ReportServerVersion'. Cannot convert value
"SQLServer2019" to type "Microsoft.ReportingServicesTools.SqlServerVersion". Error: "Unable to match the identifier name
SQLServer2019 to a valid enumerator name. Specify one of the following enumerator names and try again:
SQLServer2012, SQLServer2014, SQLServer2016, SQLServer2017, SQLServervNext"
At line:3 char:143
From here then I suppose the question is:
How do I get the module to run v15 OR how do I get version 13 of the module / namespace?
The error is being thrown from the module, but it appears to be as a result of the data we're putting into the module. Let's dive into the code to see what's happening.
I found the source code of the module here. These lines towards the bottom (85 through 102) stuck out to me:
$getWmiObjectParameters = #{
ErrorAction = "Stop"
Namespace = "root\Microsoft\SqlServer\ReportServer\RS_$ReportServerInstance\v$($ReportServerVersion.Value__)\Admin"
Class = "MSReportServer_ConfigurationSetting"
}
# code snipped
$wmiObjects = Get-WmiObject #getWmiObjectParameters
Looking back at your error, the first line is noting "invalid namespace". If anything looks immediately off in "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v13\Admin" or your values for $ReportServerInstance or $($ReportServerVersion.Value__) then I'd change those.
If those look okay to you, I'd suggest you manually search through the available WMI namespaces on the target machine. First, we want to return all the child namespaces of root.
PS C:\windows\system32> Get-WmiObject -Namespace "Root" -Class __Namespace | Select-Object -Property Name | Sort Name
Name
----
Appv
cimv2
Hardware
HyperVCluster
Microsoft
WMI
Now that we have those, we can continue searching down the path that the module is expecting. We know from the module code, it's expecting to hit "Microsoft" in the namespace/path next so add that to the namespace we're searching child namespaces for:
PS C:\windows\system32> Get-WmiObject -Namespace "Root\Microsoft" -Class __Namespace | Select-Object -Property Name | Sort Name
Name
----
HomeNet
PolicyPlatform
protectionManagement
SecurityClient
Uev
Windows
I think if you continue down that line of logic, you'll run into the spot where the module is expecting a child WMI namespace, but the target machine lacks it.
Hope this was helpful and good luck!
****Update:
To answer the new question 'How do I get the module to run v15 OR how do I get version 13 of the module / namespace?'
The example use of the cmdlet shows use of the 2-digit report server version so I'd have you try this:
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion '15'
If that returns the same error, try Connect-RsReportServer. Module documentation notes it will set/update the parameter ReportServerVersion
.PARAMETER ReportServerVersion
Specify the version of the SQL Server Reporting Services Instance.
Use the "Connect-RsReportServer" function to set/update a default value.
To troubleshoot problems with the -ReportServerVersion parameter in the ReportingServicesTools module, resulting in namespace errors, you can use the following three quick steps:
Determine the SQL server versions your server supports (replace PBIRS by your actual ReportServerInstance, if different):
Get-WmiObject -Namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS" -Class __Namespace | Select-Object -ExpandProperty Name
Example output:
V15
Display the current version to name mappings in ReportingServicesTools:
[enum]::GetValues([Microsoft.ReportingServicesTools.SqlServerVersion]) | % {[PSCustomObject]#{Name = $_;Version = $_.value__}}
Example output:
Name Version
---- -------
SQLServer2012 11
SQLServer2014 12
SQLServer2016 13
SQLServer2017 14
SQLServervNext 15
Map your supported server version to the corresponding name in the ReportingServicesTools module and use this name to pass it to the -ReportServerVersion parameter or pass the integer directly (after stripping the v).

Invoking command at dc - get gpinheritance - wont work

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.

Amazon Web Service PowerShell Credentials setup Errors

I am trying to set up my AWS on my local machine through windows PowerShell, it gives me the following error message;
PS C:\> Set-AWSCredentials -AccessKey {AAAAAAAAAAAAAAA} -SecretKey {AAAAAAAAAAAAA} -Stor
eAs {default}
Set-AWSCredentials : Cannot evaluate parameter 'AccessKey' because its argument is specified as a script block and
there is no input. A script block cannot be evaluated without input.
At line:1 char:31
+ Set-AWSCredentials -AccessKey {AAAAAAAAAAAAAAA} -SecretKey {AAAAAAAAAAAA ...
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [Set-AWSCredentials], ParameterBindingException
+ FullyQualifiedErrorId : ScriptBlockArgumentNoInput,Amazon.PowerShell.Common.SetCredentialsCmdlet
And my Powershell Version is following;
Major Minor Build Revision
----- ----- ----- --------
3 0 -1 -1
Anyone knows what the problem is?
Thanks
It looks like you need to drop the brackets from your code, the documentation from amazon that comes up first in google includes them for some reason but if you check out http://docs.aws.amazon.com/powershell/latest/reference/items/Set-AWSCredentials.html and the examples near the bottom you'll see that the function is really expecting them in a string just like any other powershell cmdlet.
Set-AWSCredentials -AccessKey AAAAAAAAAAAAAAA -SecretKey AAAAAAAAAAAAA -StoreAs default
Should do the trick for you (if there are spaces in anything make sure to wrap the string in quotes)

Setting a computer room number with a PowerShell script

Thank you all for your replies. I have corrected the errors in my code, although they were just a cut and paste error. Here is an example with the error I get. If I do for example:
PS > Set-ADComputer "VM-WINDOWS7" -Location "NA/HQ/Building A"
PS > Get-ADComputer "VM-WINDOWS7" -Properties location |select-object location
It works and I get the result:
Location
--------
NA/HQ/Building A
But when I do:
PS > Set-ADComputer "VM-WINDOWS7" -RoomNumber "7"
Or
PS > Set-ADComputer "VM-WINDOWS7" -RoomNumber #{Replace="7"}
I get the error:
Set-ADComputer: Cannot find a parameter that matches the name "RoomNumber".
At line: 1 Character: 41
+ Set-ADComputer "VM-WINDOWS7" -RoomNumber <<<< #{Replace="7"}
+ CategoryInfo: InvalidArgument: (:) [Set-ADComputer], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADComputer
It’s like I said before, the parameter RoomNumber is not recognized, so I thought maybe it has another name, like for example ( Account name in AD = SAMAccountName in PowerShell ).
You have a couple of issues here for sure. You have mistyped the AD attribute roomNumber as rooomNumber. You also have a space where your hashtable is declared.
Much like ssaviers, I see some smart quotes as well. Those can usually come from a copy and paste but you need to be careful if those are in your code.
“ - smartquote
" - regular double quote
That being said the problematic part might just need to be updated:
Set-ADComputer "$HostName" -Replace #{roomNumber = "$RoomNumber"}
Found the answer:
Set-ADComputer doesn't have a -roomnumber parameter. But it can be modified using Add, Replace, Clear or Remove parameters.
The 'ROOMNUMBER' field is LDAP so it has a different syntax:
Set-ADComputer $HostName -replace #{roomNumber='$RoomNumber'} (that's what i used in the first place but i didn’t write it correctly)
Looks like a lot of the fields in AD especially for computers need to be done this way.
Anyway thank you all for your ideas and supports.
Cheers.

Why can't I select an AliasProperty from WMI?

Given the following:
get-wmiobject win32_networkadapterconfiguration -ComputerName SERVER1,SERVER2|select pscomputername,__SERVER
Only values for __SERVER are returned. However, PSComputerName is an AliasProperty which points at __SERVER. So I expect it to return values as well (the same values as I have in __SERVER).
get-wmiobject win32_networkadapterconfiguration |gm pscomputername,__SERVER returns the following:
Name MemberType Definition
---- ---------- ----------
PSComputerName AliasProperty PSComputerName = __SERVER
__SERVER Property System.String __SERVER {get;set;}
I'm certain I've used PSComputername in the past, successfully. What am I missing here that's causing it to fail? It's happening with both PowerShell v2 & v3.
This has been asked before on some websites (see CB's comment)
and also:
Powershell PSComputerName is empty or blank when selected after invoke-command
but there is another issue I came across some time ago and never been mentioned (well not according to my Google search at that time nor now)
Are you trying to query a virtual machine?
because as far as I know and I tried, PsComputerName is absent when you query a VirtualMachine (VMware in my case).
I never found a solution for that or a workaround but I thought it will save you the time for looking one.
If you do find something though I will be more than happy to learn it :)