windows-powershell-docs
windows-powershell-docs copied to clipboard
New-ScheduledTaskSettingsSet - What is a NetworkId?
This article says we can pass a 'Network ID
', but doesn't say what that is or where we could get one from.
It'd be awesome if something explaining this could be added. =)
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 01873db6-65ca-a11d-442d-0836caca5d8e
- Version Independent ID: a1c11fee-27d9-0267-5a7a-6e0acca5d306
- Content: New-ScheduledTaskSettingsSet (scheduledtasks)
- Content Source: docset/windows/scheduledtasks/new-scheduledtasksettingsset.md
- Product: w10
- Technology: powershell-windows
- GitHub Login: @coreyp-at-msft
- Microsoft Alias: coreyp
@officedocsbot assign @e0i
@fowl2 Thank you for your feedback. Network ID is identified from the IP address and is the subnet the IP belongs to. Like Network Name, Network ID is a general term and doesn't need explanation in the doc. However, Since you have asked, Ill try to explain
If the IP address is 40.74.250.100 /18 the subnets are
subnet 1 = 40.74.0.0/18 subnet 2 = 40.74.64.0/18 subnet 3 = 40.74.128.0/18 subnet 4 = 40.74.192.0/18
So Network Id is the subnet to which the IP belongs to. In our case the network ID is 40.74.192.0/18 .
Hope this helps!
Thanks Sri
Hello @fowl2 ,
The issue is being closed since your question seems to be answered. Feel free to re-open this issue if you feel that it hasn't been answered or that there are further suggestions to improve the documentation itself.
Thanks.
@fowl2 Thank you for your feedback. Network ID is identified from the IP address and is the subnet the IP belongs to. Like Network Name, Network ID is a general term and doesn't need explanation in the doc. However, Since you have asked, Ill try to explain
If the IP address is 40.74.250.100 /18 the subnets are
subnet 1 = 40.74.0.0/18 subnet 2 = 40.74.64.0/18 subnet 3 = 40.74.128.0/18 subnet 4 = 40.74.192.0/18
So Network Id is the subnet to which the IP belongs to. In our case the network ID is 40.74.192.0/18 .
Hope this helps!
Thanks Sri
-NetworkName Specifies the name of a network profile that Task Scheduler uses to determine if the task can run. The Task Scheduler UI uses this setting for display purposes. Specify a network name if you specify the RunOnlyIfNetworkAvailable parameter https://learn.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtasksettingsset?view=windowsserver2022-ps#-networkid
<NetworkSettings>
<Name>WiFi-SSID</Name>
<Id>01873db6-65ca-a11d-442d-0836caca5d8e</Id>
</NetworkSettings>
I have not manages to find the ID but I see it in the XML file if I export my task from Task Scheduler.
Update... The ID is found in registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles
It seems that @Orava2 has found some additional evidence that network ID actually refers to a Network List Manager Network ID, which is a GUID referring to a network profile.
All the Task Scheduler docs seem to concur, with it being a GUID at least: Id (networkSettingsType) Element / INetworkSettings::get_Id / NetworkSettings.Id. No mention of where you might get one though.
It seems like INetworkListManager::GetNetworks + INetwork::GetNetworkId might be what we need.
Get-NetConnectionProfile returns an object with a InstanceID
property, but that doesn't seem to match the registry entries.
I found some code here to call it:
$NetworkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID('DCB00C01-570F-4A9B-8D69-199FDBA5723B'))
# Set enums for GetNetworks
$NLM_ENUM_NETWORK_CONNECTED=1
$NLM_ENUM_NETWORK_DISCONNECTED=2
$NLM_ENUM_NETWORK_ALL=3
$Networks = $NetworkListManager.GetNetworks($NLM_ENUM_NETWORK_CONNECTED)
foreach($Network in $Networks){
$Network.GetName()
$Network.GetNetworkId()
}
It retrieves the names file, but for some reason getting the ID fails, on my machine at least:
Value does not fall within the expected range. At line:3 char:3
- $Network.GetNetworkId()
- CategoryInfo : OperationStopped: (:) [], ArgumentException
- FullyQualifiedErrorId : System.ArgumentException
My investigation ends here, but it definitely seems like the documentation could be improved!
@JasonGerend it appears that you are the new owner for these docs, could you take a look?
To make it easier for you to submit feedback on articles on learn.microsoft.com, we're transitioning our feedback system from GitHub Issues to a new experience.
As part of the transition, this GitHub Issue will be moved to a private repository. We're moving Issues to another repository so we can continue working on Issues that were open at the time of the transition. When this Issue is moved, you'll no longer be able to access it.
If you want to provide additional information before this Issue is moved, please update this Issue before December 15th, 2023.
With the new experience, you no longer need to sign in to GitHub to enter and submit your feedback. Instead, you can choose directly on each article's page whether the article was helpful. Then you can then choose one or more reasons for your feedback and optionally provide additional context before you select Submit.
Here's what the new experience looks like.
Note: The new experience is being rolled out across learn.microsoft.com in phases. If you don't see the new experience on an article, please check back later.
First, select whether the article was helpful:
Then, choose at least one reason for your feedback and optionally provide additional details about your feedback:
Article was helpful | Article was unhelpful |
---|---|
![]() |
![]() |
Finally, select Submit and you're done!
Quick and dirty way to get the network ID from the registry based on the above comments:
$path = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\'
$sids = Get-ItemProperty -Path ($path + '*') | Select-Object -ExpandProperty PSChildName
$network = foreach ($item in $sids) {Get-ItemProperty -Path ($path + '\' + $item) | Where {$_.Description -like "whatever"}}
Description worked for us. Use whatever parameters you want I am 100% sure someone better than I am at powershell can write something cleaner
Your Settings line would have:
$settings = New-ScheduledTaskSettingsSet -RunOnlyIfNetworkAvailable -NetworkID ($network.PSChildName).trim('{}') -NetworkName $network.ProfileName
The .trim() above seems to be unnecessary as it worked with and without it. I have left it in
Your final Register-ScheduledTask would look something like:
Register-ScheduledTask -Trigger $trigger -Action $action -TaskName 'Task Name Here' -Principal $principal -Settings $settings
Tested working with our network description I used a disabled VPN adapter as the test "fail" case, which successfully prevented it from running. It failed with error 0x800704c6 as it should