Hello all, first time posting on the forums (so please forgive any mistakes ).
I currently have two different powershell scripts that my department uses based on the the location of the user (US/India). The only difference is one has some different file zipping/transfer based on the location of some network drives.
I was looking to combine them into one with an IF statement based on the Get-WinHomeLocation function, compare value that back to pre-defined GeoIDs for the US and India, but I am having trouble qualifying the variable/object type of the GeoID to something useful that I can define.
#Define US/India GeoID's
$USID = 0xF4
$IndiaID = 0x71
#Determine GeoID of user's computer
$GeoID = Get-WinHomeLocation
#$GeoID = 0xF4
#Addiitonal script for US users.
if ($GeoID -eq $USID) {
Write-Output "Hello GreenMonkies!"
}
I have tried casting the GeoID to a string, an Int32 (based on the Set-WinHomeLocation literature I read). Any help on how to either assign the “$USID” variable to something that can be compared to the GeoID or another way to achieve this funcitonality would be greatly appreciated.
The return value you get from the cmdlet Get-WinHomeLocation is not a HEX value. It is an object with two properties - GeoId ( what’s an [INT] ) and HomeLocation ( what’s a [STRING] ).
But you can use the output more directly if you like … like this for example:
$WinHomeLocation = Get-WinHomeLocation
"The current GeoId is '$($WinHomeLocation.GeoId)' and the according Location is '$($WinHomeLocation.HomeLocation)'."
Olaf, thank you for this! It is exactly what I was looking for. I was using the information on Microsoft’s website and I guess I didn’t understand that the “Outputs” section referred to properties I could reference from the Get-WinHomeLocation object. I do see that this link does not show the HomeLocation property listed. Is there a more comprehensive resource easily available for Powershell? I looked at the guide in the open discussions page, but didn’t see anything about the Get-WinHomeLocation cmdlet.
Seems like you have found a bug in the documentation. I’d recommend to file this bug on GitHub to get it fixed.
Usually the official help is the most reliable source of information about a particular cmdlet. But the PowerShell team are only humans … the do make mistakes sometimes.
In this case you should have noticed when you simply run the command in the console.
From looking at the GitHub document, it does not seem as if it is meant to be comprehensive, but instead more exploratory to help build fundamentals. I can certainly help point out that it is missing information about the Get-WinHomeLocation cmdlet if that is not the case.
Very understandable that there are gaps in the official help. I think the biggest problem is my relative lack of experience in Powershell and not knowing that the GeoId and HomeLocation were referring to properties I could call from the Get-WinHomeLocation cmdlet.
Again, thanks for the help, sometimes it’s hard to know what you don’t know until someone points it out