I'm troubleshooting Win10 PCs getting bad location information. The Windows Geolocation service puts them in Colorado when they should be in California. That changes the time zone and they miss meetings.
Anyway, I'm looking for the data that is being fed into the Geolocation service to see what could be causing the bad results. I think that the info will be in the Position source. The doc is here.
And I would like to be able to access in the object in PowerShell for troubleshooting.
I can do something similar with the geolocation output which will show me the longitude and latitude like this:
Add-Type -AssemblyName System.Device
$GeoWatcher = New-Object System.Device.Location.GeoCoordinateWatcher
$GeoWatcher.Start()
Can anyone "translate" how to load the correct assemblies for the Positionsource?
Note, if you are doing this on office locked user, meaning, desktops/laptops/mobile devices, then it's going to report the location based on the egress gateway / external IPA, not the actual host location.
Yet, this sounds like a possible duplicate of this answer:
Powershell: Getting GPS Coordinates in Windows 10 - Using Windows Location API?
# Required to access System.Device.Location namespace
Add-Type -AssemblyName System.Device
# Create the required object
$GeoWatcher = New-Object System.Device.Location.GeoCoordinateWatcher
# Begin resolving current locaton
$GeoWatcher.Start()
while (($GeoWatcher.Status -ne 'Ready') -and ($GeoWatcher.Permission -ne 'Denied'))
{
#Wait for discovery.
Start-Sleep -Milliseconds 100
}
if ($GeoWatcher.Permission -eq 'Denied')
{Write-Error 'Access Denied for Location Information'}
else
{
#Select the relevent results.
$GeoWatcher.Position.Location |
Select Latitude,Longitude
}
Yet, see the MS doc here:
PositionSource Enum
Indicates the source used to obtain a Geocoordinate.
Definition
Namespace : Windows.Devices.Geolocation
Assemblies : Windows.Devices.Geolocation.dll, Windows.dll
Geocoordinate Class
Contains the information for identifying a geographic location.
Definition
Namespace : Windows.Devices.Geolocation
Assemblies : Windows.Devices.Geolocation.dll, Windows.dll
Related
I have written 9 routines in the last few weeks in Powershell for Domino, they all appear to do what I need except 1!
This is the RegisterNewUser method, which does everything except the Email address. If I setup a user via Domino Administrator, I get everything including the email address ie internal address that is 'bob patz/smallhome'.
If I use my code this uses the registration process but all I end up with is the domain part of the internal email address '#smallhome'.
Does anyone know how to correct this? I don't think powershell uses the #formula language in any form, so I assume i somehow need to find the right column in a document or database and append the fullname in there somehow.
Is there anyone out there who can help in anyway?
regards
Mark
<#TOP TIP: THIS MUST RUN UNDER POWERSHELL (X86), ELSE IT WILL NOT WORK!!
This Powershell Function was created in March 2020 by (myself) Mark Baker as 'a' just to see if I can de-mystify
some of the Domino Database stucture, after running short bits of code and using Get-Member on some parts
of it and looking at online code snippets and reading some of the online info from IBM I have come up with
the function below to Create a New Lotus Notes User.
#
Original Code: 31/03/2020 by MBaker
A lot of work testing and diagnosing the different settings and values EVENTUALLY lead me to getting this working,
as at 08/04/2020 I just need to work out the settings for setting the correct email address per person.
#
This is how to use this function:
New-DominoUserRegistration "hazell" "C:\Program Files\IBM\Lotus\Notes\Data\ids\people\dhazell.id" "CN=Dom-01/O=Smallhome"
"Daniel" "" "swindon" "Work" "comment" "mail\dhazell" " " "password" 176
"dhazell"
Main use of this function is to connect to an IBM Domino Server and Create a New lotus notes user.
>
Function New-DominoUserRegistration {
[cmdletbinding()]
param (
[parameter(Position=0,Mandatory=$true,ValueFromPipeline=$True)][string]$lastname,
[parameter(Position=1,Mandatory=$true,ValueFromPipeline=$True)][string]$Useridfile,
[parameter(Position=2,Mandatory=$true,ValueFromPipeline=$True)][string]$mailserver,
[parameter(Position=3,Mandatory=$true,ValueFromPipeline=$True)][string]$firstname,
[parameter(Position=4,Mandatory=$false,ValueFromPipeline=$True)][string]$middle,
[parameter(Position=5,Mandatory=$true,ValueFromPipeline=$True)][string]$certpw,
[parameter(Position=6,Mandatory=$true,ValueFromPipeline=$True)][string]$location,
[parameter(Position=7,Mandatory=$true,ValueFromPipeline=$True)][string]$comment,
[parameter(Position=8,Mandatory=$true,ValueFromPipeline=$True)][string]$maildbpath,
[parameter(Position=9,Mandatory=$true,ValueFromPipeline=$True)][string]$fwddomain,
[parameter(Position=10,Mandatory=$true,ValueFromPipeline=$True)][string]$userpw,
[parameter(Position=11,Mandatory=$true,ValueFromPipeline=$True)][int]$usertype,
[parameter(Position=12,Mandatory=$true,ValueFromPipeline=$True)][string]$ShortName
)
cls
# Create Lotus Notes Object
$DomSession = New-Object -ComObject Lotus.NotesSession
# Initialize Lotus Notes Object
# "It'll use your open notes session and authentication Details"
$DomSession.Initialize()
# Use Method from Objects returned in variable $domsession one of which is CreateAdministrationProcess which
# takes a Server as input
$adminProcess = $Domsession.CreateRegistration()
$expiration = (Get-Date).adddays(1095)
$adminprocess.certifieridfile="C:\Program Files (x86)\IBM\Lotus\Notes\Data\ids\cert.id"
$adminprocess.Expiration =$expiration
#$adminprocess.RegistrationLog ="C:\program files (x86)\IBM\lotus\notes\data\reglog.nsf"
#[int]$adminProcess.MinPasswordLength=5
$adminprocess.RegistrationServer="Dom-01/smallhome"
$adminprocess.UpdateAddressBook=$true
$adminProcess.GroupList="Test4"
#$adminProcess.CreateMailDb=$true
#[int]$adminProcess.MailQuotaSizeLimit="100"
#[int]$adminProcess.MailQuotaWarningThreshold="90"
$adminProcess.PolicyName="/Registration_Settings"
$adminProcess.ShortName=$ShortName
[int]$adminProcess.MailOwnerAccess=2
$adminProcess.MailACLManager="LocalDomainAdmins"
$adminProcess.MailInternetAddress="$ShortName"+"#smallhome.local"
$adminProcess.MailTemplateName="Mail85.ntf"
$Notesid=$adminprocess.RegisterNewUser($lastname,$Useridfile,$mailserver,$firstname,$middle,$certpw,$location,$comment,$maildbpath,$fwddomain,$userpw,$usertype)
}
New-DominoUserRegistration "archer" "C:\Program Files (x86)\IBM\Lotus\Notes\Data\ids\people\barcher.id" "CN=Dom-01/O=Smallhome" "basil" "" "swindon" "Work" "comment" "mail\barcher" " " "password" 176 "barcher"
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/2Wamq.png
I now have an answer for this, this came from someone else on another board: the line [parameter(Position=9,Mandatory=$true,ValueFromPipeline=$True)][string]$fwddomain,
Needed to have [AllowEmptyString()] inserted before [string]$fwddomain, and the input field was " " and needed to be "". It appears the $fwddomain has an impact on the internal email address name ie: 'bob patz/smallhome'.
I have tested this and it shows up in the people view and also I can now send emails to other users and ones self!
Problem solved.
Regards
Mark
I am trying to deploy an Azure VM based off of the "Visual Studio 2019 Latest" image. Initially it had an error in the template where the version was just being called "latest". I replaced this value with the correct value that I obtained from Get-AzVMImage cmdlet. The error then went away (PlatformImageNotFound error). Now when I attempt to redeploy with the correct value in the template, it quickly errors out with: SubscriptionNotAuthorizedForImage
A google shows that this error comes from, surprise surprise, the subscription not being authorized for the image. How do I get authorization? In my subscription I have enabled resource providers to just about every one that I could imagine would be relevant, and still no dice. In the description it says that you must be a VS subscriber, but I am one. I have also looked to see the purchase plan variable in the Get-AzVMImage cmdlet, and it shows null (meaning that there are not any additional terms that need to be accepted before use).
More frustratingly, nobody else seems to have had this issue. Does anyone have any recommendations?
{
"error": {
"code": "SubscriptionNotAuthorizedForImage",
"message": "The subscription is not authorized.",
"target": "imageReference"
}
}
Any help would be greatly appreciated.
There are some regions which might not be available for your subscription. If you change the region to something very common like "US East" it works. Even if it works in a specific region, the chosen machine size might not be available.
I had this exact problem; various regions didn't work - UK West, UK South, North Europe, not even US East. Eventually I tried a Windows Server machine (in US East) instead of Win10 and that worked. Here is the image reference I used.
"imageReference": {
"publisher": "microsoftvisualstudio",
"offer": "visualstudio2019",
"sku": "vs-2019-ent-ws2019",
"version": "latest"
}
I'm not totally clear on what was causing this error for me, but there may be a few reasons for this. Worth checking:
Image is not available in your chosen location.
You're using an MSDN or other restricted type of subscription.
The image you're trying to deploy is designed for Hyper-V Gen 1, but your VM Size only supports Gen 2.
I was getting the OPs error and firstly switched from an MSDN subscription to an EA subscription, which resulted in a different error, pertaining to the Hyper-V generation.
Sometimes it can be very hard to find specific images in the Portal. Some images don't even exist in the Portal and even if you do find the image, the UI seems to use version = latest and that doesn't work for all images.
There are four parts to specifying the image. Often the version is overlooked. There is also something called a URN which concatenates these with a :. See here, however, I have never used this in ARM JSON, Terraform or PowerShell. Maybe something for Bicep or AzCLI.
Publisher
Offer
Sku
Version
Standard Windows OS images are fairly easy, so I'll use a harder one to find to demonstrate: Microsoft SQL Server 2014, SP2, Enterprise. I couldn't find this exact image in the portal.
1. List publishers for uksouth region:
# It's a safe bet the image is published by Microsoft
$Location = "uksouth"
Get-AzVmImagePublisher -Location $Location | Where-Object{$_.PublisherName -like "*Microsoft*"}
This returns ~411 publishers with Microsoft in the name. The best contender is MicrosoftSQLServer.
2. List offers for MicrosoftSQLServer:
$Location = "uksouth"
$Publisher = "MicrosoftSQLServer"
Get-AzVmImageOffer -Location $Location -PublisherName $Publisher
This whittles it down to ~34 SQL-related images. To make it a little clearer, I'll add a filter:
Get-AzVmImageOffer -Location $Location -PublisherName $Publisher | Where-Object{$_.Offer -like "*2014*"}
I now have 4 possible images:
3. Get Image SKUs:
$Location = "uksouth"
$Publisher = "MicrosoftSQLServer"
$Offer = "SQL2014SP2-WS2012R2-BYOL"
Get-AzVMImageSku -Location $Location -PublisherName $Publisher -Offer $Offer
This returns 2 possible options:
Surely, this means the image is available. Why would Microsoft list an image that isn't actually deployable? So why do we get the error:
The platform image 'MicrosoftSqlServer:SQL2014SP2-WS2012R2-BYOL:Enterprise:latest' is not available.
Verify that all fields in the storage profile are correct.
For more details about storage profile information, please refer to https://aka.ms/storageprofile ErrorCode: PlatformImageNotFound ErrorMessage:
The platform image 'MicrosoftSqlServer:SQL2014SP2-WS2012R2-BYOL:Enterprise:latest' is not available. Verify that all fields in the storage profile are correct.
For more details about storage profile information, please refer to
https://aka.ms/storageprofile ErrorTarget: imageReference StatusCode: 404 ReasonPhrase:
Not Found OperationID : cea13334-878b-49ad-8934-ff75ccdbf623
The clue is in the URN:
MicrosoftSqlServer:SQL2014SP2-WS2012R2-BYOL:Enterprise:latest
And what I have found to be the problem: latest
4. Get the image version:
Armed with the Publisher, Offer and Sku, we can find the available versions.
$Location = "uksouth"
$Publisher = "MicrosoftSQLServer"
$Offer = "SQL2014SP2-WS2012R2-BYOL"
$Sku = "Enterprise"
Get-AzVMImage -Location $Location -PublisherName $Publisher -Offer $Offer -Skus $Sku
This results in several versions:
I am not 100% sure what format the version number follows. It seems to be a timestamp. I assume the last one in the list is the "latest". Note, none of them shows as latest, however, this is true for images where version = latest is known to work and not surprising.
More information can be gleaned by adding -Version to the last cmdlet:
$Location = "uksouth"
$Publisher = "MicrosoftSQLServer"
$Offer = "SQL2014SP2-WS2012R2-BYOL"
$Sku = "Enterprise"
$Version = "12.21.210914"
Get-AzVMImage -Location $Location -PublisherName $Publisher -Offer $Offer -Skus $Sku -Version $Version
Resulting in the following:
Note
The PurchasePlan is null, but this may be a gotcha for non-Microsoft images where an additional cost is incurred and one has to accept the vendor's T&C's. See here.
In this example, HyperVGeneration = v1. Be aware that some VM sizes do not support Gen 1. The error is fairly obvious for this though:
The selected VM size 'Standard_DC4s_v2' cannot boot Hypervisor Generation '1'. If this was a Create operation please check that the Hypervisor Generation of the
Image matches the Hypervisor Generation of the selected VM Size. If this was an Update operation please select a Hypervisor Generation '1' VM Size. ErrorCode:
BadRequest ErrorMessage: The selected VM size 'Standard_DC4s_v2' cannot boot Hypervisor Generation '1'. If this was a Create operation please check that the
Hypervisor Generation of the Image matches the Hypervisor Generation of the selected VM Size. If this was an Update operation please select a Hypervisor
Generation '1' VM Size. ErrorTarget: StatusCode: 400 ReasonPhrase: Bad Request OperationID : 06f9c9a6-c9bb-4c83-87aa-9d1b7392a171
5. Deploy the image:
I'm not going to list all the cmdlets for deploying a VM, but the main one for image selection is:
$Location = "uksouth"
$Publisher = "MicrosoftSQLServer"
$Offer = "SQL2014SP2-WS2012R2-BYOL"
$Sku = "Enterprise"
$Version = "12.21.210914"
Set-AzVMSourceImage -VM $oVM -PublisherName $Publisher -Offer $Offer -Skus $Sku -Version $Version
Finally, the deployed VM:
I'm trying to figure our why a call to Set-Acl in powershell failes.
The call is part of a larger script used in setting up an AD OU. The basic steps of that scripts are:
Create a new OU
Add a group to that OU
Create a folder on a file share.
Add permissions for the newly created group to that newly created folder.
Copy the content of a template folder to the newly folder.
Create a DFS folder to pointing to the new folder.
The script works fine except for a call to SetACL:
#Some initialization data. In reality, the exact values are generated using the script parameters.
$NewDataPath="\\server\share\folder\"
$NewGroupName="UserGroup_1234"
#The actual code from the original script
$Acl = Get-Acl $NewDataPath
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($NewGroupName, "Modify", "ContainerInherit,ObjectInherit", "None", "Allow")
#exception happens on the following line
$Acl.SetAccessRule($Ar)
#whetever happens afterward works fine
Set-Acl -Path $NewDataPath $Acl
This raises the following exception:
Exception calling "SetAccessRule" with "1" argument(s): "Some or all
identity references could not be translated."
+ $Acl.SetAccessRule <<<< ($Ar)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
The really weird thing is that if I run each line manually, it works. I have moved the code to a separate function and calling it manually after the initial code fails (with the exact same parameter) works as well.
Even weirder: if I move the section of code that update the permissions AFTER I have copied data into it, it works.
It is as if the SetAccessRule method call (or perhaps the FileSystemAccessRule object) wasn't able to access the new data in AD, even though all other calls works fine and if a slight delay is introduce, it recovers.
While I was able to find a workaround, I'd really would like to understand what is happening here.
This seems to be a typical race-like condition when creating multiple new AD objects that depend on each other.
I haven't confirmed this, but I suspect that when you supply an account name as a string to the FileSystemAccessRule constructor, .NET uses the LSA Lookup Cache on your machine to resolve the name to a security identifier.
Since you literally just created the account on another machine (the DC) a few hundred milliseconds ago, the lookup cache fails to translate the name.
You can easily circumvent this by supplying the Security Identifier of the new account instead.
To get the SID, specify the -PassThru switch when you create the group, this will return the new object (including it's SID):
$NewGroupInstance = New-ADGroup -Name $NewGroupName -PassThru # -Path and so forth
# ...
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($NewGroupInstance.SID, "Modify", "ContainerInherit,ObjectInherit", "None", "Allow")
I'm trying to install COM + Component using powershell. But I'm getting following error.
Unable to find type [some.dll]. Make sure that the assembly that contains this
type is loaded.
+ $comAdmin.InstallComponent("test", [some.dll]);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (COMITSServer.dll:TypeName) [], Runtime
Exception
+ FullyQualifiedErrorId : TypeNotFound
and here is my powershell script:
Install COM + Components
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog;
$comAdmin.InstallComponent("some", [some.dll]);
#if an exception occurs in installing COM+ then display the message below
if (!$?)
{
Write-Host "Unable to Install the COM+ Component. Aborting..."
exit -1
}
My powershell version is 4.0
Can someone please help me on this.
Thank you.
Square brackets in PowerShell indicate a type, like [string] or [int32] or [System.Array] or [System.Math]. The error message is complaining because you're telling PowerShell that COMITSServer.dll is a registered and loaded data type.
Additionally, the InstallComponent method of COMAdminCatalog appears to me to have four arguments, not two. You should be able to confirm that by looking at the definition, but I don't know if v2.0 supports doing it like this:
PS U:\> $comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
PS U:\> $comAdmin | gm | where { $_.Name -eq 'InstallComponent' }
TypeName: System.__ComObject#{790c6e0b-9194-4cc9-9426-a48a63185696}
Name MemberType Definition
---- ---------- ----------
InstallComponent Method void InstallComponent (string, string, string, string)
As such, I would try this:
$comAdmin.InstallComponent("ITSServerOO2", "COMITSServer.dll", "", "");
That appears to be how the VB code here calls the same method:
' Open a session with the catalog.
' Instantiate a COMAdminCatalog object.
Dim objCatalog As COMAdminCatalog
Set objCatalog = CreateObject("COMAdmin.COMAdminCatalog")
[...]
' Install components into the application.
' Use the InstallComponent method on COMAdminCatalog.
' In this case, the last two parameters are passed as empty strings.
objCatalog.InstallComponent "MyHomeZoo","MyZoo.DLL","",""
Here is the class definition of that function, I believe, athough I'm not familiar enough with COM+ to know if COMAdminCatalog and ICOMAdminCatalog are the same.
This is an answer to the question about the 0x80110401 HRESULT. (BTW, follow up questions should be answered in a new post on SO, not in the comments of an existing question). This allows other people to find answers when they have the same question.
Documentation for ICOMAdminCatalog::InstallComponent. As the documentation explains the first parameter is GUID, the second is the DLL being registered. The third parameter (typelib) and fourth (proxy stub DLL) are optional and can be specified as an empty string.
"test" is not a valid GUID. Note that a GUID is a distinct .NET type (System.Guid). However the documentation calls for a BSTR which would translate into a System.String. To get a new GUID as a string use this: [Guid]::NewGuid().toString().
Note that GUIDs for COM+ components are "well known" values that are used by both the COM servers implementing an interface(s) and by clients that are consuming the interface(s) from a COM server. So normally you wouldn't want to generate a new GUID when registering a COM server, but use the one the developer created when the COM server was developed. However if you don't know what the correct GUID to use is, then generating a new GUID will at least allow you to make progress in developing your script.
This may or may not fix the problem causing the 0x80110401, but it will definitely fix a problem you'll run into sooner or later.
I am developing a windows application which gives the field details --> X.
Where X is -->
Right Click My Computer >
Properties >
Device Manager > (select any Item - Say KeyBoard) >
Click it > standard PS/2 KeyBoard >
double Click standard PS/2 KeyBoard >
click the Details Tab >
Under the Property there are various fields like Display Name , Problem Code,Parent Siblings, etc , etc?
I want to get their values .
Which Windows API I can use for this.
I am doing this for windows 7 as well as windows 8.I hope the API will remain the same.Also i am having 64 bit machine.
This has to be true for any device whose details I wanted to know from the Device Manager.
ALso I just want to all operations - Reading and No Set (writing) so I think I will not be having any problem with violating the Admin Rights.PLease suggest.! I have added Snapshots for reference!Say for example I want to know the current State of the HID USB Complaint Mouse(D0(Active) or D2(Sleep)).
I need to Get this Power State D0.
The question is tagged with C#, though the actual question asks for any Window API. With the Win32 API the information can be retrieved with SetupDiGetDeviceRegistryProperty(). The steps would be:
Get a device info set for the devices you're interested in via SetupDiGetClassDevs().
Iterate through the device infos via SetupDiEnumDeviceInfo().
Get the properties via calls to SetupDiGetDeviceRegistryProperty().
Destroy the device info set via SetupDiDestroyDeviceInfoList().
According to the documentation the API is available on Windows 2000 and later.
It's quite easy to get the hardware information using ManagementObjectCollection.
For instance to get all properties and values from the PC processor
var win32DeviceClassName = "win32_processor";
var query = string.Format("select * from {0}", win32DeviceClassName);
using (var searcher = new ManagementObjectSearcher(query))
{
ManagementObjectCollection objectCollection = searcher.Get();
foreach (ManagementBaseObject managementBaseObject in objectCollection)
{
foreach (PropertyData propertyData in managementBaseObject.Properties)
{
Console.WriteLine("Property: {0}, Value: {1}", propertyData.Name, propertyData.Value);
}
}
}
The full list of WIN32 class name is available at http://msdn.microsoft.com/en-us/library/aa394084%28v=VS.85%29.aspx
Cheers.
You're going to have the easiest time (I think) doing this with PowerShell. If you are writing some C# code you can execute a PS script using types in the System.Management.Automation namespace, such as PowerShell (link: http://msdn.microsoft.com/en-us/library/system.management.automation.powershell(v=vs.85).aspx) but I would begin your testing using the PS Console.
You should first (using PowerShell) explore the WMI objects in your environments using this command
Get-WmiObject -List -namespace root\CIMV2
Then once you identify with class you are looking for you can retrieve details on that class using this command:
Get-WmiObject -namespace root\CIMV2 -class Win32_USBControllerDevice
Once you have that content you'd have to parse the text.
UPDATE: Try using this command to get the "State", "Status", and "Started" attributes of mouse drivers on your PC:
gwmi Win32_SystemDriver | where {$_.DisplayName -like "*Mouse*"}