get-counter with locale independent IDs - powershell

I am trying to access the following counter-path via the cmdlet get-counter in a locale-independent way:
\Memory\Pool Nonpaged Bytes
I followed the instructions in this thread to archive this. And so I looked up the two IDs for the counter-path in the registry and got \4\58
But unfortunately this path won't work. I always get the error-message
The specified performance-indicator could not be found
The path from the other thread \238(_Total)\6 works perfectly fine! But for my path I can only get \4\* to list all counters in the set.
What am I doing wrong?

#Chris,
PowerShell Magazine carried an article on this a while ago.
http://www.powershellmagazine.com/2013/07/19/querying-performance-counters-from-powershell/
Tobias showed a way to translate counter names to ID numbers.

Related

Powershell - The Parameter "XXXX" is declared in parameter-set "__AllParameterSets" multiple times

First of all, i'm sorry if this question has been posted before.
I couldn't seem to find and answer we could work with, so here goes..
Backstory:
Every 90 days all password of the NT-accounts will expire.
The office staff gets a notification when they're signing in into Windows 10.
However our iPad users (salesmen and technicians who are on the road) don't get a notification about the expiration.
They use an app which requires a NT-account to sign into our sales system.
Now we've found a Powershell script which would e-mail the user about the expiration of his password, but unfortunately we keep getting the following error:
"The parameter "testing" is declared in parameter-set "__AllParameterSets" multiple times."
As we do not have any Powershell programming skills, we have no idea what going wrong in the script.
Could you guys help us?
The following script is being used (ofcourse edited with our SMTP server and e-mail addresses).
https://gallery.technet.microsoft.com/scriptcenter/Password-Expiry-Email-177c3e27
Much obliged :-)
the code you 1st linked to never, EVER mentions parameter sets. not once. [grin]
the code in your 2nd link mentions it # 106 = __AllParameterSets.
that it IS NOT a parameter set attribute, but is some "other thing". it looks like a call to something in python.
there is no other mention anywhere in your linked code of that __AllParameterSets thing.
so, the fix is to remove it OR to rename it something that does not use a powershell keyword. [grin]

How to detect new print jobs in Windows queue using Powershell

I am looking for a way, using PowerShell, to detect when a new print job arrives in a print queue. Have been searching for the past couple of days and the best I've come up with is reference to a "PRINTER_CHANGE_ADD_JOB" flag here but nothing about how to use it.
I would like to be able to do something like threads that talk about registering for an event to watch for new files in a folder (e.g. this TechNet article using System.IO.FileSystemWatcher).
Is there something comparable for print queues? Any example code, or even pointers to articles or tutorials, would be greatly appreciated. I've only started into PowerShell a couple of months ago.
if you have a print server then you can use the PowerShell PrintManagment Module https://learn.microsoft.com/en-us/powershell/module/printmanagement/?view=win10-ps.
Regards
Shihan
As far as i am aware i dont think there is any built in PowerShell cmdlets to get what you want. but you can script it either using the Get-PrintJob Module or you can use WMI to get this information. If you want to be notified you can either write to the event log or pipe the output out to send-mailmessage and send you a email notification when a print job is in error.
Get-WMIObject Win32_PerfFormattedData_Spooler_PrintQueue |Select Name, #{Expression={$_.jobs};Label="CurrentJobs"}, TotalJobsPrinted, JobErrors

Can I enable / Disable an Azure Service Bus Topic using Powershell

I have spent a couple of hours search for a solution to disable my Azure Service Bus Topics using Powershell.
The background for this is we want to force a manual failover to our other region.
Obviously I could click in the Portal:
but I want to have a script to do this.
Here is my current attempt:
Any help would be great.
Assuming you're sure your $topic contains the full description, modify the status parameter in the array and then splat it back using the UpdateTopic method. I'm afraid I can't test this at present.
$topic.Status = "Disabled"
$topicdesc = $NamespaceManager.UpdateTopic($topic)
I don't think you'll need to set the entity type for the Status, nor do you require semi-colons after each line of code in your loop.
References
PowerShell Service Bus creation sample script (which this appears to be based off): https://blogs.msdn.microsoft.com/paolos/2014/12/02/how-to-create-service-bus-queues-topics-and-subscriptions-using-a-powershell-script/
UpdateTopic method: https://msdn.microsoft.com/en-us/library/azure/microsoft.servicebus.namespacemanager.updatetopic.aspx
Additional note: please don't screenshot the code - paste it in. I'd rather copy-and-paste than type things out.

Obtaining Solaris Device path

I am working on Solaris 12 and I am trying to get device path like this:
/pci#0,0/pci108e,4856#1f,2:devctl
I could obtain the this path through CLI using prtconf -v. How could I obtain the path through api using C function? I tried serveral functions in libdevinfo, such as di_devfs_path, but it didn't give the same path as the prtconf gives me. Should I use functions like di_node_name, di_instance, di_binding_name to get pieces of information and construct the path by my own. Or there is a function to get the whole device path?
Thanks.
Firstly, unless you're working for Oracle in the Systems division, you're not working on Solaris 12. (If you are working for Oracle, why haven't you asked
Oracle internal mailing lists for help?)
Secondly, the :devctl node is a minor for the device, so you'll need to walk the minor nodes using di_walk_minor() and check di_minor_name() to see if it matches your criteria.
Finally, yes, this should work on Solaris 10 and later.

Error when re-declaring item as record via PowerShell - "The file has been modified "SHAREPOINT\system"

We have had a PowerShell script scheduled and executing successfully for the past 3-4 months (In both Test and Prod). The purpose of the script is to update document properties in SharePoint when certain triggers are fired from external systems. Without getting into too much detail, below is the code that has been used to update item properties for a document that has been declared a record:
$recordsmanagement=[Microsoft.Office.RecordsManagement.RecordsRepository.Records]
$recordsmanagement::UndeclareItemAsRecord($item)
$item = $list.GetItemById($item.id)
$item.File.CheckOut()
$item[$sSpFieldName]=$sDbValue
$item.Update()
$item = $list.GetItemById($item.id)
$item.File.CheckIn("")
$recordsmanagement::DeclareItemAsRecord($item)
This code has worked hundreds of times without a problem. For some reason, this code started bombing a week ago on the last line (when re-declaring as a record):
System.Management.Automation.MethodInvocationException: Exception calling "DeclareItemAsRecord" with "1" argument(s): "The file /lib/folder/file.pdf has been modified by SHAREPOINT\system on 10 Oct 2012 00:00:47 -0500."
The other weird part is that this is only happening in Prod. The Test environment seems to execute just fine. I haven't tried a fix for production yet, but I'm pretty sure I can just get the $item object again using GetItemById (after the CheckIn). I'm a little hesitant to do this just yet as I wanted to get some other people's perspective first.
Does anyone have any input on this? Thanks in advance.
I think the best bet is to get the item again after the checkin as you say.
The error message indicates exactly that. You are trying to perform an operation on a SPListItem that has been modified. So pull it again using GetItemById before you declare it as a record.
Why it only happens on some records and on some environment I am not sure. I guess Sharepoint is a bit temperamental.
Thing I would try as well:
Check if there is any workflow doing some work on that item when you check it in
Try to use SystemUpdate() instead of Update() if that suits your requirements
Good luck