I have a new installation of Exchange 2016 Enterprise, Mailbox role (single server, no other servers in the infrastructure). Everything works fine but I need to make some configurations for which I need the commands Get-ReceiveConnector and Set-ReceiveConnector. However when I try to execute these commands in the Exchange Management Shell I get an error:
[PS] C:\Windows\system32>Get-ReceiveConnector
Get-ReceiveConnector : The term 'Get-ReceiveConnector' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
Get-ReceiveConnector
~~~~~~~~~~~~~~~~~~~~
CategoryInfo : ObjectNotFound: (Get-ReceiveConnector:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
I can execute other Exchange commands successfully and Get-ExCommand gives me a long list of supported commands, but not the two I need:
[PS] C:\Windows\system32>Get-ExCommand
CommandType Name Version
----------- ---- -------
Function Add-DistributionGroupMember 1.0
Function Add-MailboxFolderPermission 1.0
Function Clear-ActiveSyncDevice 1.0
Function Clear-MobileDevice 1.0
Function Clear-TextMessagingAccount 1.0
Function Compare-TextMessagingVerificationCode 1.0
Function ConvertFrom-SddlString 3.1.0.0
Function Disable-App 1.0
Function Disable-InboxRule 1.0
Function Disable-UMCallAnsweringRule 1.0
Function Enable-App 1.0
Function Enable-InboxRule 1.0
Function Enable-UMCallAnsweringRule 1.0
Function Format-Hex 3.1.0.0
Function Get-ActiveSyncDevice 1.0
Function Get-ActiveSyncDeviceStatistics 1.0
Function Get-App 1.0
Function Get-CalendarNotification 1.0
Function Get-CalendarProcessing 1.0
Function Get-CASMailbox 1.0
Function Get-ConsumerMailbox 1.0
Function Get-DistributionGroup 1.0
Function Get-DistributionGroupMember 1.0
Function Get-FileHash 3.1.0.0
Function Get-Group 1.0
Function Get-InboxRule 1.0
Function Get-Mailbox 1.0
Function Get-MailboxAutoReplyConfiguration 1.0
Function Get-MailboxCalendarConfiguration 1.0
Function Get-MailboxCalendarFolder 1.0
Function Get-MailboxFolder 1.0
Function Get-MailboxFolderPermission 1.0
Function Get-MailboxJunkEmailConfiguration 1.0
Function Get-MailboxMessageConfiguration 1.0
Function Get-MailboxPreferredLocation 1.0
Function Get-MailboxRegionalConfiguration 1.0
Function Get-MailboxSpellingConfiguration 1.0
Function Get-MailboxStatistics 1.0
Function Get-MessageCategory 1.0
Function Get-MessageClassification 1.0
Function Get-MessageTrackingReport 1.0
Function Get-MobileDevice 1.0
Function Get-MobileDeviceStatistics 1.0
Function Get-OnlineMeetingConfiguration 1.0
Function Get-RbacDiagnosticInfo 1.0
Function Get-Recipient 1.0
Function Get-SiteMailbox 1.0
Function Get-SiteMailboxDiagnostics 1.0
Function Get-TextMessagingAccount 1.0
Function Get-UMCallAnsweringRule 1.0
Function Get-UMMailbox 1.0
Function Get-UMMailboxConfiguration 1.0
Function Get-UMPhoneSession 1.0
Function Get-UnifiedAuditSetting 1.0
Function Get-User 1.0
Function Get-UserPhoto 1.0
Function Import-PowerShellDataFile 3.1.0.0
Function Import-RecipientDataProperty 1.0
Function New-App 1.0
Function New-Guid 3.1.0.0
Function New-InboxRule 1.0
Function New-MailboxFolder 1.0
Function New-MailMessage 1.0
Function New-SiteMailbox 1.0
Function New-TemporaryFile 3.1.0.0
Function New-UMCallAnsweringRule 1.0
Function PSConsoleHostReadline 1.2
Function Remove-ActiveSyncDevice 1.0
Function Remove-App 1.0
Function Remove-DistributionGroupMember 1.0
Function Remove-InboxRule 1.0
Function Remove-MailboxFolderPermission 1.0
Function Remove-MobileDevice 1.0
Function Remove-UMCallAnsweringRule 1.0
Function Remove-UserPhoto 1.0
Function Search-MessageTrackingReport 1.0
Function Send-TextMessagingVerificationCode 1.0
Function Set-CalendarNotification 1.0
Function Set-CalendarProcessing 1.0
Function Set-CASMailbox 1.0
Function Set-ConsumerMailbox 1.0
Function Set-InboxRule 1.0
Function Set-Mailbox 1.0
Function Set-MailboxAutoReplyConfiguration 1.0
Function Set-MailboxCalendarConfiguration 1.0
Function Set-MailboxCalendarFolder 1.0
Function Set-MailboxFolderPermission 1.0
Function Set-MailboxJunkEmailConfiguration 1.0
Function Set-MailboxMessageConfiguration 1.0
Function Set-MailboxRegionalConfiguration 1.0
Function Set-MailboxSpellingConfiguration 1.0
Function Set-MailUser 1.0
Function Set-SiteMailbox 1.0
Function Set-TextMessagingAccount 1.0
Function Set-UMCallAnsweringRule 1.0
Function Set-UMMailbox 1.0
Function Set-UMMailboxConfiguration 1.0
Function Set-UMMailboxPIN 1.0
Function Set-UnifiedAuditSetting 1.0
Function Set-User 1.0
Function Set-UserPhoto 1.0
Function Start-AuditAssistant 1.0
Function Start-UMPhoneSession 1.0
Function Stop-UMPhoneSession 1.0
Function Test-SiteMailbox 1.0
Function Update-SiteMailbox 1.0
Cmdlet Add-Computer 3.1.0.0
Cmdlet Add-Content 3.1.0.0
Cmdlet Add-Member 3.1.0.0
Cmdlet Add-Type 3.1.0.0
Cmdlet Checkpoint-Computer 3.1.0.0
Cmdlet Clear-Content 3.1.0.0
Cmdlet Clear-EventLog 3.1.0.0
Cmdlet Clear-Item 3.1.0.0
Cmdlet Clear-ItemProperty 3.1.0.0
Cmdlet Clear-RecycleBin 3.1.0.0
Cmdlet Clear-Variable 3.1.0.0
Cmdlet Compare-Object 3.1.0.0
Cmdlet Complete-Transaction 3.1.0.0
Cmdlet ConvertFrom-Csv 3.1.0.0
Cmdlet ConvertFrom-Json 3.1.0.0
Cmdlet ConvertFrom-String 3.1.0.0
Cmdlet ConvertFrom-StringData 3.1.0.0
Cmdlet Convert-Path 3.1.0.0
Cmdlet Convert-String 3.1.0.0
Cmdlet ConvertTo-Csv 3.1.0.0
Cmdlet ConvertTo-Html 3.1.0.0
Cmdlet ConvertTo-Json 3.1.0.0
Cmdlet ConvertTo-Xml 3.1.0.0
Cmdlet Copy-Item 3.1.0.0
Cmdlet Copy-ItemProperty 3.1.0.0
Cmdlet Debug-Process 3.1.0.0
Cmdlet Debug-Runspace 3.1.0.0
Cmdlet Disable-ComputerRestore 3.1.0.0
Cmdlet Disable-PSBreakpoint 3.1.0.0
Cmdlet Disable-RunspaceDebug 3.1.0.0
Cmdlet Enable-ComputerRestore 3.1.0.0
Cmdlet Enable-PSBreakpoint 3.1.0.0
Cmdlet Enable-RunspaceDebug 3.1.0.0
Cmdlet Export-Alias 3.1.0.0
Cmdlet Export-Clixml 3.1.0.0
Cmdlet Export-Csv 3.1.0.0
Cmdlet Export-FormatData 3.1.0.0
Cmdlet Export-PSSession 3.1.0.0
Cmdlet Format-Custom 3.1.0.0
Cmdlet Format-List 3.1.0.0
Cmdlet Format-Table 3.1.0.0
Cmdlet Format-Wide 3.1.0.0
Cmdlet Get-Alias 3.1.0.0
Cmdlet Get-ChildItem 3.1.0.0
Cmdlet Get-Clipboard 3.1.0.0
Cmdlet Get-ComputerInfo 3.1.0.0
Cmdlet Get-ComputerRestorePoint 3.1.0.0
Cmdlet Get-Content 3.1.0.0
Cmdlet Get-ControlPanelItem 3.1.0.0
Cmdlet Get-Culture 3.1.0.0
Cmdlet Get-Date 3.1.0.0
Cmdlet Get-Event 3.1.0.0
Cmdlet Get-EventLog 3.1.0.0
Cmdlet Get-EventSubscriber 3.1.0.0
Cmdlet Get-FormatData 3.1.0.0
Cmdlet Get-Host 3.1.0.0
Cmdlet Get-HotFix 3.1.0.0
Cmdlet Get-Item 3.1.0.0
Cmdlet Get-ItemProperty 3.1.0.0
Cmdlet Get-ItemPropertyValue 3.1.0.0
Cmdlet Get-Location 3.1.0.0
Cmdlet Get-Member 3.1.0.0
Cmdlet Get-Process 3.1.0.0
Cmdlet Get-PSBreakpoint 3.1.0.0
Cmdlet Get-PSCallStack 3.1.0.0
Cmdlet Get-PSDrive 3.1.0.0
Cmdlet Get-PSProvider 3.1.0.0
Cmdlet Get-PSReadlineKeyHandler 1.2
Cmdlet Get-PSReadlineOption 1.2
Cmdlet Get-Random 3.1.0.0
Cmdlet Get-Runspace 3.1.0.0
Cmdlet Get-RunspaceDebug 3.1.0.0
Cmdlet Get-Service 3.1.0.0
Cmdlet Get-TimeZone 3.1.0.0
Cmdlet Get-TraceSource 3.1.0.0
Cmdlet Get-Transaction 3.1.0.0
Cmdlet Get-TypeData 3.1.0.0
Cmdlet Get-UICulture 3.1.0.0
Cmdlet Get-Unique 3.1.0.0
Cmdlet Get-Variable 3.1.0.0
Cmdlet Get-WmiObject 3.1.0.0
Cmdlet Group-Object 3.1.0.0
Cmdlet Import-Alias 3.1.0.0
Cmdlet Import-Clixml 3.1.0.0
Cmdlet Import-Csv 3.1.0.0
Cmdlet Import-LocalizedData 3.1.0.0
Cmdlet Import-PSSession 3.1.0.0
Cmdlet Invoke-Expression 3.1.0.0
Cmdlet Invoke-Item 3.1.0.0
Cmdlet Invoke-RestMethod 3.1.0.0
Cmdlet Invoke-WebRequest 3.1.0.0
Cmdlet Invoke-WmiMethod 3.1.0.0
Cmdlet Join-Path 3.1.0.0
Cmdlet Limit-EventLog 3.1.0.0
Cmdlet Measure-Command 3.1.0.0
Cmdlet Measure-Object 3.1.0.0
Cmdlet Move-Item 3.1.0.0
Cmdlet Move-ItemProperty 3.1.0.0
Cmdlet New-Alias 3.1.0.0
Cmdlet New-Event 3.1.0.0
Cmdlet New-EventLog 3.1.0.0
Cmdlet New-Item 3.1.0.0
Cmdlet New-ItemProperty 3.1.0.0
Cmdlet New-Object 3.1.0.0
Cmdlet New-PSDrive 3.1.0.0
Cmdlet New-Service 3.1.0.0
Cmdlet New-TimeSpan 3.1.0.0
Cmdlet New-Variable 3.1.0.0
Cmdlet New-WebServiceProxy 3.1.0.0
Cmdlet Out-File 3.1.0.0
Cmdlet Out-GridView 3.1.0.0
Cmdlet Out-Printer 3.1.0.0
Cmdlet Out-String 3.1.0.0
Cmdlet Pop-Location 3.1.0.0
Cmdlet Push-Location 3.1.0.0
Cmdlet Read-Host 3.1.0.0
Cmdlet Register-EngineEvent 3.1.0.0
Cmdlet Register-ObjectEvent 3.1.0.0
Cmdlet Register-WmiEvent 3.1.0.0
Cmdlet Remove-Computer 3.1.0.0
Cmdlet Remove-Event 3.1.0.0
Cmdlet Remove-EventLog 3.1.0.0
Cmdlet Remove-Item 3.1.0.0
Cmdlet Remove-ItemProperty 3.1.0.0
Cmdlet Remove-PSBreakpoint 3.1.0.0
Cmdlet Remove-PSDrive 3.1.0.0
Cmdlet Remove-PSReadlineKeyHandler 1.2
Cmdlet Remove-TypeData 3.1.0.0
Cmdlet Remove-Variable 3.1.0.0
Cmdlet Remove-WmiObject 3.1.0.0
Cmdlet Rename-Computer 3.1.0.0
Cmdlet Rename-Item 3.1.0.0
Cmdlet Rename-ItemProperty 3.1.0.0
Cmdlet Reset-ComputerMachinePassword 3.1.0.0
Cmdlet Resolve-Path 3.1.0.0
Cmdlet Restart-Computer 3.1.0.0
Cmdlet Restart-Service 3.1.0.0
Cmdlet Restore-Computer 3.1.0.0
Cmdlet Resume-Service 3.1.0.0
Cmdlet Select-Object 3.1.0.0
Cmdlet Select-String 3.1.0.0
Cmdlet Select-Xml 3.1.0.0
Cmdlet Send-MailMessage 3.1.0.0
Cmdlet Set-Alias 3.1.0.0
Cmdlet Set-Clipboard 3.1.0.0
Cmdlet Set-Content 3.1.0.0
Cmdlet Set-Date 3.1.0.0
Cmdlet Set-Item 3.1.0.0
Cmdlet Set-ItemProperty 3.1.0.0
Cmdlet Set-Location 3.1.0.0
Cmdlet Set-PSBreakpoint 3.1.0.0
Cmdlet Set-PSReadlineKeyHandler 1.2
Cmdlet Set-PSReadlineOption 1.2
Cmdlet Set-Service 3.1.0.0
Cmdlet Set-TimeZone 3.1.0.0
Cmdlet Set-TraceSource 3.1.0.0
Cmdlet Set-Variable 3.1.0.0
Cmdlet Set-WmiInstance 3.1.0.0
Cmdlet Show-Command 3.1.0.0
Cmdlet Show-ControlPanelItem 3.1.0.0
Cmdlet Show-EventLog 3.1.0.0
Cmdlet Sort-Object 3.1.0.0
Cmdlet Split-Path 3.1.0.0
Cmdlet Start-Process 3.1.0.0
Cmdlet Start-Service 3.1.0.0
Cmdlet Start-Sleep 3.1.0.0
Cmdlet Start-Transaction 3.1.0.0
Cmdlet Stop-Computer 3.1.0.0
Cmdlet Stop-Process 3.1.0.0
Cmdlet Stop-Service 3.1.0.0
Cmdlet Suspend-Service 3.1.0.0
Cmdlet Tee-Object 3.1.0.0
Cmdlet Test-ComputerSecureChannel 3.1.0.0
Cmdlet Test-Connection 3.1.0.0
Cmdlet Test-Path 3.1.0.0
Cmdlet Trace-Command 3.1.0.0
Cmdlet Unblock-File 3.1.0.0
Cmdlet Undo-Transaction 3.1.0.0
Cmdlet Unregister-Event 3.1.0.0
Cmdlet Update-FormatData 3.1.0.0
Cmdlet Update-List 3.1.0.0
Cmdlet Update-TypeData 3.1.0.0
Cmdlet Use-Transaction 3.1.0.0
Cmdlet Wait-Debugger 3.1.0.0
Cmdlet Wait-Event 3.1.0.0
Cmdlet Wait-Process 3.1.0.0
Cmdlet Write-Debug 3.1.0.0
Cmdlet Write-Error 3.1.0.0
Cmdlet Write-EventLog 3.1.0.0
Cmdlet Write-Host 3.1.0.0
Cmdlet Write-Information 3.1.0.0
Cmdlet Write-Output 3.1.0.0
Cmdlet Write-Progress 3.1.0.0
Cmdlet Write-Verbose 3.1.0.0
Cmdlet Write-Warning 3.1.0.0
How can I get Get-ReceiveConnector and Set-ReceiveConnector to work?
I came across this post https://tigermatt.wordpress.com/2010/11/11/missing-some-cmdlets-at-exchange-management-shell-me-too/ and it says that it's a user profile issue.
I tried using another user (the domain administrator) and everything works fine, so it's really a problem of my user. However, deleting the folder as suggested in the article didn't work.
What worked was adding additional roles to my user, especially the Organization Management and Enterprise Admins and now everything works fine.
Related
I would like to change some settings for the Windows Desktop View via Powershell. Unfortunately, this does not work at all. Currently I would like to change the following things:
Unpin group from Start
Unpin group from Start
My approach:
Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount\ | Where-Object {$_.Name -like "*start.tilegrid$windows.data.curatedtilecollection.tilecollection*"} | Remove-Item -Force -Recurse
Notifications "Expand" and "Clear all notifications"
Notifications "Expand" and "Clear all notifications"
My approach:
Set-ItemProperty -Path "HKCU:\Control Panel\Quick Actions\Control Center\QuickActionsStateCapture" -Name "Toggles" -Type String -Value "Toggles,Microsoft.QuickAction.Location:false,Microsoft.QuickAction.BlueLightReduction:false,Microsoft.QuickAction.AllSettings:false,Microsoft.QuickAction.AvailableNetworks:false,Microsoft.QuickAction.Connect:false,Microsoft.QuickAction.Project:false,Microsoft.QuickAction.Vpn:false,Microsoft.QuickAction.QuietHours:false,Microsoft.QuickAction.ScreenClipping:false" -Force
Task Manager
Task Manager > More details
Performance > CPU > Change graph to > Logical processors
My approach:
New-Item -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name TaskManager –Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\TaskManager" -Name "StartUpTab" -Type DWord -Value 1 -Force
Language
Remove Languages
Download Language pack, Handwriting, Speech
My approach:
Add-WindowsPackage -Online -PackagePath .\lp_de-CH.cab
$ll = New-WinUserLanguageList -Language $language
Set-WinUserLanguageList $ll -Force
$LangList = Get-WinUserLanguageList
$MarkedLang = $LangList | where LanguageTag -eq "fr-CH"
$LangList.Remove($MarkedLang)
$MarkedLang = $LangList | where LanguageTag -eq "en-us"
$LangList.Remove($MarkedLang)
Unfortunately, it does not work with it. Does anyone have an idea about one of the points?
Thank you very much and best regards
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am working on updates for Win 7 x64 ultimate. I have a text file in which I have typed KBnnnnn one entry per line. I want sort of a script/loop to go through each entry in text file and find it in installed updates. If found append a new text file with HotFixID, Description, date etc and status='INSTALLED'. If not found, status='NOT INSTALLED'
Later I want to selectively uninstall specific HotFixes by simial loop process reading each entry from a text file and uninstalling it, updating status on screen and in another text log file. I am very new to PowerShell, tried to create a loop in cmd batch scripting using WMIC but no success yet.
Why are you not using WSUS for this? It is why it exists.
There are modules in the MS powershellgallery.com for this kind of use case well.
Find-Module -Name '*WSUS*' | Format-Table -AutoSize
Version Name Repository Description
------- ---- ---------- -----------
2.3.1.6 PoshWSUS PSGallery PowerShell module to manage a WSUS Server. Support site: https://github.com/proxb/PoshWSUS/
1.1.0 ecs.wsus PSGallery This Windows PowerShell module contains ECS.WSUS funtions
0.4.4 PSWsusSpringClean PSGallery Give your WSUS server a thorough spring cleaning
0.9.0 PSWSUSMigration PSGallery Powershell module to help WSUS (Windows Server Update Services) server migration. Support site: https://github.com/reiikei/PSWSUSMigration
I am working on updates for Win 7 x64 ultimate.
So, what version of PowerShell are you using on Win7?
I have a text file in which I have typed KBnnnnn one entry per line.
OK, a standard file that can be easily read using Import-Csv or Get-Content. Yet, why are you doing this? There is a cmdlet called Get-HotFix specifically for this.
# All Help topics and locations
Get-Help about_*
Get-Help about_Functions
Get-Help about* | Select Name, Synopsis
Get-Help about* |
Select-Object -Property Name, Synopsis |
Out-GridView -Title 'Select Topic' -OutputMode Multiple |
ForEach-Object { Get-Help -Name $_.Name -ShowWindow }
explorer "$pshome\$($Host.CurrentCulture.Name)"
# Get parameters, examples, full and Online help for a cmdlet or function
# Get a list of all functions
Get-Command -CommandType Function |
Out-GridView -PassThru -Title 'Available functions'
# Get a list of all commandlets
Get-Command -CommandType Cmdlet |
Out-GridView -PassThru -Title 'Available cmdlets'
# get function / cmdlet details
Get-Command -Name Import-Csv -Syntax
(Get-Command -Name Import-Csv).Parameters.Keys
Get-help -Name Import-Csv -Full
Get-help -Name Import-Csv -Online
Get-help -Name Import-Csv -Examples
Get-Command -Name Get-Content -Syntax
(Get-Command -Name Get-Content).Parameters.Keys
Get-help -Name Get-Content -Full
Get-help -Name Get-Content -Online
Get-help -Name Get-Content -Examples
Get-Command -Name Get-Hotfix -Syntax
(Get-Command -Name Get-Hotfix).Parameters.Keys
Get-help -Name Get-Hotfix -Full
Get-help -Name Get-Hotfix -Online
Get-help -Name Get-Hotfix -Examples
I want sort of a script/loop
Sure, you can do this.
About ForEach
Each of the above help files has examples of loops.
to go through each entry in text file and find it in installed
updates.
OK, this is a common thing. A PowerShell very beginner thing, with lots of articles, samples and videos all over the web for this and shown in the help cmdlet, resources, etc., shown.
If found append a new text file with HotFixID, Description, date etc.,
and status='INSTALLED'. If not found, status='NOT INSTALLED'
Again, nothing new or complicated here and again a very common thing and done via the -Append switch or the Add-Content cmdlet.
Get-Command -Name Add-Content -Syntax
(Get-Command -Name Add-Content).Parameters.Keys
Get-help -Name Add-Content -Full
Get-help -Name Add-Content -Online
Get-help -Name Add-Content -Examples
later I want to selectively uninstall specific HotFixes by simial loop
process reading each entry from a text file and uninstalling it,
Again, nothing new or complicated here and again a very common thing. You do this via a comparison block/command in your code.
About Comparison Operators
updating status on screen and in another text log file.
Again, nothing new or complicated here and again a very common thing. This is what Out-File or Export-Csv, or Start-Transcript or writing your own logger is for and using progress bars. Lots of articles, blogs, videos ho how to do this.
Script Write-Log PowerShell Logging Function
Get-Command -Name Write-Progress -Syntax
(Get-Command -Name Write-Progress).Parameters.Keys
Get-help -Name Write-Progress -Full
Get-help -Name Write-Progress -Online
Get-help -Name Write-Progress -Examples
I am very new to PowerShell, tried to create a loop in cmd batch
scripting using WMIC but no success yet.
OK, this is fine. It means you should spend time learning it first and there are plenty of free text-based and video-based (YouTube videos, MSDN videos, etc.) for you to use. All it requires is that you search for it, use them as-is and or tweak as needed.
'powershell windows hotfix management'
'Beginning PowerShell'
'Intermediate PowerShell'
'Advanced PowerShell'
'PowerShell file and folder management'
'PowerShell hotfix report'
Sample scripts
'powershellgallery.com hotfix management'
'wmic find hotfix'
'vbscript wmic hotfix management'
The question here is, why are you using WMIC, vs Powershell directly? Hence the cmdlets above. One can use WMIC without ever using PowerShell at all, in .bat/cmd/vbs files as has been done for years.
You say you've done batch file programming, It's good to see you dip into the PowerShell pool, but that does not mean you can't stick with batch to do what you need and then convert that to PowerShell now or later.
Update based on you code comment
If you did this in the console/ISE/VSCode, it just works as it would from cmd.exe
wmic qfe get hotfixid > d:\temp\QfElist.txt
Get-content -Path 'd:\temp\QfElist.txt'
<#
Results
KB4537572
KB4513661
...
#>
But you could have just done this and gotten something far more useable
Get-HotFix
<#
# Results
Source Description HotFixID InstalledBy InstalledOn
------ ----------- -------- ----------- -----------
LP70 Update KB4537572 NT AUTHORITY\SYSTEM 11-Mar-20 00:00:00
LP70 Update KB4513661 09-Sep-19 00:00:00
LP70 Security Update KB4515383 09-Sep-19 00:00:00
...
#>
Comparing this against a file is just as simple. Let's say your file looks like this.
$KBCheckList = '
KB4537572
KB4513661
KB4515400
' | Out-File -FilePath 'D:\Temp\KBCheckList.txt'
Now read the file, using this
Get-Content -Path 'D:\Temp\KBCheckList.txt'
<#
# Results
KdId
KB4537572
KB4513661
KB4515400
#>
or this
Import-Csv -Path 'D:\Temp\KBCheckList.txt'
<#
# Results
WARNING: One or more headers were not specified. Default names starting with "H" have been used in place of any missing headers.
H1
--
KB4537572
KB4513661
KB4515400
#>
You can see the difference is minor (visually) but Csv file needs a header (and really should be properly formatted first). Either add it to the top of the file or add it on the fly
Import-Csv -Path 'D:\Temp\KBCheckList.txt' -Header 'KBID'
<#
# Results
KBID
----
KB4537572
KB4513661
KB4515400
#>
All the above is just educational stuff for you. You only really need one of the two below, or similar.
Now just use the file. Read in a loop and use if/then or try/catch statement to get results
Import-Csv -Path 'D:\Temp\KBCheckList.txt' -Header 'KBID' |
ForEach {
$PSItem.KBID
}
<#
# Results
KB4537572
KB4513661
KB4515400
#>
or just compare the file list to the results of the cmdlet
$QfeData = Get-Hotfix
$KBCheckList = Import-Csv -Path 'D:\Temp\KBCheckList.txt' -Header 'KBID'
Compare-Object -ReferenceObject $QfeData.HotFixID -DifferenceObject $KBCheckList.KBID
<#
# Results
InputObject SideIndicator
----------- -------------
KB4515400 => *** this means that this ID is only in the DifferenceObject which is your file, thus not installed.
KB4515383 <=
KB4516115 <=
KB4517245 <=
KB4521863 <=
KB4524244 <=
KB4524569 <=
KB4525419 <=
KB4528759 <=
KB4537759 <=
KB4538674 <=
KB4541338 <=
KB4551762 <=
#>
I've got a simple script that looks for a file across a bunch of servers. Issue is that on each server it is pegging CPU and causing issues for production workloads. How can I get this script to not DDoS my machines?!
Start-transcript C:\tools\Querylog.txt
$Servers = Get-ADComputer -Filter {(OperatingSystem -like "*windows*server*") -and (Enabled -eq "True")} -Properties OperatingSystem
Invoke-command -ComputerName $Server-ScriptBlock {Get-ChildItem -Path $_.Root -Recurse -Force -File -ErrorAction SilentlyContinue | Where-Object { $_.Name -like '*somefile-readme*' } |Out-File -FilePath <filePath>\results.txt -Append}
Stop-Transcript
Use the -Filter option with Get-ChildItem, it should be much more performant than returning all objects and filtering with Where-Object.
Also, not related to your CPU issue but in how you are crafting your Get-ADComputer call, you should use a String, not a ScriptBlock for the -Filter arguments on these cmdlets. From that answer:
-Filter doesn't support ScriptBlocks, but they Kind of Work Sometimes™ because they get ToString'd before getting evaluated. They will technically work if you use simple variable expansion like $_ or $emailAddress, but it will eventually cause you a headache, especially if you try to access an object property (like above) because it simply won't work. Use a string filter every time, and if you need to use an object property as a filter parameter, use Variable Substitution or Command Substitution.
I need a way to programatically (powershell, batch, c#, ...) tell my VPN adapter that it has to register address in DNS.
There seems to be no parameter for this using PowerShell to create the VPN entry:
Powershell.exe -executionpolicy bypass -command Add-VpnConnection -AllUserConnection -Name "ProfileName" -ServerAddress "xyz.com" -TunnelType L2tp -EncryptionLevel Optional -L2tpPsk "password" -AuthenticationMethod MSChapv2 -Force
We had no success doing this by GPO, netsh or c# (DotRas -> VpnEntry.Options.RegisterIPWithDns = true;)
Thanks in advance!
As far as I know there are no way of doing it with the Add-VpnConnection command.
Instead you have to edit the Remote Access Phonebook.
If it is a -alluserconnection VPN the phonebook can be found here:
C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk
If it is a per user VPN adapter the phonebook can be found here:
C:\Users\USERNAME\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk
Now use this Powershell command to set the setting:
$RASPhoneBook =
“C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk”
(Get-Content $RASPhoneBook) -Replace ‘IpDnsFlags=0’, ‘IpDnsFlags=3’ |
Set-Content $RASPhoneBook
“Register this connection’s addresses in DNS” is now set for your VPN adapter.
Try something like this
Get-NetIPConfiguration | where {$_.some.identifying.vpn.feature -eq 'name'} | Get-NetConnectionProfile | Set-DnsClient -RegisterThisConnectionsAddress:$True
I'd suggest using a different approach for your use case.
Example:
Using PowerShell to Get or Set NetworkAdapterConfiguration-View and Change Network Settings Including DHCP, DNS, IP Address and More (Dynamic AND Static) Step-By-Step
Following commands can be useful to configure the settings:
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -Property [a-z]* -ExcludeProperty IPX*,WINS*
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "FullDNSRegistrationEnabled=true" –ComputerName . | Get-Member
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "DomainDNSRegistrationEnabled=true" –ComputerName . | Get-Member
I want to move the Favorites folder from a folder that changes its folder guid daily from Appsense.
Text between quotes changes.
C:\appsensevirtual\S-1-5-21-220523388-2000478354-839522115-60875\'{647CFC75-E4C0-4F13-9888-C37BA083416C}'\_Microsoft Office 2010
I have found this but it never copies to the H: (Homedrive).
Get-ChildItem "C:\Appsensevirtual" -Recurse -Filter "Favorites*" -Directory |
Move-Item -Destination "H:\Favorites"
If i run I get this in an Powershell Administrator Window (powershell 2)
PS C:\temp> .\favorites.ps1
Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'.
At C:\temp\favorites.ps1:1 char:76
+ Get-ChildItem "C:\Appsensevirtual" -Recurse -Filter "Favorites*" -Directory <<<< | Move-Item -Destination "H:\Favorites"
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
You solution is:
Remove -Directory from your command, and add -Force which will parse system & hidden folders.
Get-ChildItem "C:\Appsensevirtual" -Recurse -Filter "Favorites*" -Force |
Move-Item -Destination "H:\Favorites"