PowerShell version of Webpartmanager.Savechanges(????)

Hi,
I am facing similar issue listed in 
http://sharepoint.stackexchange.com/questions/92619/paging-in-xsltlistviewwebpart-is-not-working-perfectly-when-added-programmatical
As per MSFT Forums, savechanges takes one parameter as input ie. Webpart
https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.webpartpages.splimitedwebpartmanager.savechanges(v=office.15).aspx
but when I try with I get exception 
'ERROR
An error occured during the placement of the AddListViewWebPart: Cannot convert argument "webPart", with value: "d0b13021-437a-49d2-a64d-a594af7f5ffa", for "SaveChanges" to
type "System.Web.UI.WebControls.WebParts.WebPart": "Cannot convert the "d0b13021-437a-49d2-a64d-a594af7f5ffa" value of type "System.Guid" to type "System.Web.UI.WebControls.WebParts.WebPart"."
which basically asking to give parameter of type 'System.Web.UI.WebControls.WebParts.WebPart"'
Also, when I try to pass object of type System.Web.UI.WebControls.WebParts.WebPart" - I get an exception
'object reference not set to instance of object' as listed in below URL.
http://sharepoint.stackexchange.com/questions/130421/pagination-not-working-with-xsltviewwebpart-when-created-using-powershell
Please advice.

Hi SGMSSharePoint,
I saw the thread in stackexchange that you mentioned had an anwser from the creator, maybe the creator was you.
The scirpt is:
function SaveChanges($siteUrl, $pageUrl,$viewName)
$web = Get-SPWeb $siteUrl
$publishingWeb =
[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
# Check if the page already exists
$currentPage = $publishingWeb.GetPublishingPages() | Where { $_.Url -eq $pageUrl}
CheckOutPage -spFile $currentPage.ListItem.File -allowUndoCheckout $false
$webPartProperty_Visible = $true
$web = get-spweb $siteUrl
$defaultPage = $web.GetFile($pageUrl)
# Get the LimitedWebPartManager
$webpartmanager = $defaultPage.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
#Deleting existing web part
foreach ($webpart in ($webpartmanager.WebParts | Where-Object {$_.Title -eq $viewName}))
write-host $siteUrl +"Saving WebPart" + $webpart.Title + " : " + $webpart.ID
$webpartmanager.SaveChanges($webPart)
break;
CheckInPage -spFile $currentPage.ListItem.File
$web.Update();
$web.Dispose()
Please have a look at:
http://sharepoint.stackexchange.com/questions/130421/pagination-not-working-with-xsltviewwebpart-when-created-using-powershell
If you have any update for this issue, please let me know.
Best Regards,
Wendy
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Wendy Li
TechNet Community Support

Similar Messages

  • Build numbers for powershell.exe vs. PowerShell version

    Hi!
    I'm looking for information about powershell.exe file build number or version than can allow mi determine installed PowerShell version on remote hosts.
    Currently I must determine installed version on a lot of servers that I can only get information about files versions. It is in the secure envinroment that some ports are filtered. On server is installed Windows Server 2003 (R2) or Windows Sever 2008 R2
    - some have PowerShell installed but not all.
    Thank you in advance.
    Wojciech Sciesinski

    Hi,
    Just checking in to see if the suggestions were helpful. Please let us know if you would like further assistance.
    TechNet Subscriber Support
    If you are
    TechNet Subscription
    user and have any feedback on our support quality, please send your feedback
    here.
    Regards, Yan Li

  • Powershell versions

    Agreed with Nicolas - v2 to v3 is huge and if you are doing this in a lab environment, go ahead and jump to v4 - but at a minimum, get to v3.  Not only are there a lot more cmdlets, but some of the syntax was changed between the versions in order to ensure consistency going forward I believe.

    Hi!
    Yes you can face issues while working on a version and running the same script with another powershell version.
    I would highly recommend to upgrade your 2K8R2 to a V3 (the gap between V2 and V3 is huge, less important between V3 to V4).
    On your VM you can run powershell on a specific version, by running (Win+R):
    Textpowershell -version 2
    This will launch a V2 powershell, so you can test your scripts that way.
    The fact is that some cmdlets does not exists on V2, or some of them works in a slightly different way that could change a lot of things.

  • Server 2008 R2 Powershell version 4 cannot use Get-Net* (anything) commands

    Brand new to PS here.
    I have a new install of 2008R2 and have updated to Powershell 4 by installing Windows
    Management Framework 4.0. The system has DotNET 4.5.1 on it as well.
    I am trying to run a script for setting IP which is part of the example shown in the following blog:
    http://blogs.technet.com/b/heyscriptingguy/archive/2013/01/03/use-powershell-to-deploy-a-new-active-directory-forest.aspx
    So far I have run into a brick wall as I am unable to break the code for using the Get-NetAdapter command.
    In the example, the following is shown:
      $ipif = (Get-NetAdapter).ifIndex  New-NetIPAddress -IPAddress $ipaddress -PrefixLength $ipprefix -InterfaceIndex $ipif -DefaultGateway $ipgw
    When running the script, PS errors with
    "Get-NetAdapter : The term 'Get-NetAdapter' is not recognized as the name of a cmdlet, function, script file, or operable program"
    I found that by using "$ipif = Get-Command -Module NetAdapter -InterfaceIndex" , I get nothing. When I use the PowerShell ISE, no error
    is given either and the Intellisense feature is no help.
    I have executed
    Get-Module on my system and this is the output:
    ModuleType Version    Name                              
                ExportedCommands                                        
    Script     1.0.0.0    ISE                                
                       {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}     
    Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear...
    Manifest   3.0.0.0    Microsoft.PowerShell.Security              {ConvertFrom-SecureString, ConvertTo-SecureString,
    Get...
    Manifest   3.1.0.0    Microsoft.PowerShell.Utility                {Add-Member, Add-Type, Clear-Variable,
    Compare-Object...}
    Manifest   3.0.0.0    Microsoft.WSMan.Management             {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan...
    Executing the command
    $psversiontable returns the following:
    Name                           Value
    PSVersion                      4.0
    WSManStackVersion       3.0
    SerializationVersion        1.1.0.1
    CLRVersion                    4.0.30319.18408
    BuildVersion                   6.3.9600.16406
    PSCompatibleVersions    {1.0, 2.0, 3.0, 4.0}
    PSRemotingProtocolVersion      2.2
    I would welcome suggestions, comments and/or pointers for the correct direction in which to travel.
    Thanks in advance

    another joke from Microsoft...... there are many documents on the TechNet referring to Windows Management Framework 4.0 containing NetAdapter cmdlet... even pointing to the right download location.... but forget to mention that the damn thing does
    not work on Windows Server 2008 environment... again... a joke
    It's right at the top of the documentation page for the cmdlets.
    http://technet.microsoft.com/en-us/library/jj130867.aspx
    Perhaps you need to get your eyes checked.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Exchange 2013 remote session running as PowerShell version 2.0. How can I get it to run version 3.0?

    I'm trying to use the newer Powershell 3.0 features, particularly the ability to disconnect/reconnect a remote session, for our Exchange 2013 administration tools.  I have 3.0 on my workstation, and am connecting to a remote session on an Exchange 2013
    server (on Server 2012).   Even LOCALLY on the Exchange 2013 server Exchange Management Shell I get the same behavior:
    Exchange Command Shell on an Exchange 2013 server (running Windows Server 2012)
    [PS] >$PSVersionTable
    Name                           Value
    PSVersion                      3.0
    WSManStackVersion              3.0
    SerializationVersion           1.1.0.1
    CLRVersion                     4.0.30319.19117
    BuildVersion                   6.2.9200.16628
    PSCompatibleVersions           {1.0, 2.0, 3.0}
    PSRemotingProtocolVersion      2.2
    [PS] C:\Windows\system32>Get-PSSession
     Id Name            ComputerName    State         ConfigurationName
      1 Session1        mercmbx35r.n... Opened        Microsoft.Exchange
    [PS] C:\Windows\system32>$session = Get-PSSession
    [PS] C:\Windows\system32>$session.ApplicationPrivateData.PSVersionTable
    Name                           Value
    PSVersion                      2.0
    PSCompatibleVersions           {1.0, 2.0, 3.0}
    PSRemotingProtocolVersion      2.2
    BuildVersion                   6.2.9200.16628
    CLRVersion                     4.0.30319.19117
    WSManStackVersion              3.0
    SerializationVersion           1.1.0.1
    How/where can I force the Exchange session to run version 3.0?
    Thanks in advance,
    Rick Tatem

    I still can't get it to work that way. I changed my cfexecute to:
    <cfexecute name="C:\windows\system32\cmd.exe" arguments="/c C:\Inetpub\wwwroot\captcha\#cmd_filename#" outputFile="C:\testoutput.txt" timeout = "90"></cfexecute>
    And I changed my bat file to have:
    <cfsavecontent variable="cmd_content">
    cd\
    TSC.exe /s "#newString#" C:\Inetpub\wwwroot\captcha\#FileName# Mary (for Telephone)
    </cfsavecontent>
    The output file is showing:
    C:\ColdFusion9\runtime\bin>cd\
    C:\>TSC.exe /s "3.....P.....4.....Z.....8.....U.....7.....X....." C:\Inetpub\wwwroot\captcha\3P4Z8U7X-105724.wav Mary (for Telephone)
    I still can't get it to run the exe. I have watched the process list while running this and the exe doesn't show up. I tried cfexecute on the exe directly before trying the bat method, with hard coded arguments, and it still didn't work. I am so lost right now this makes no sense to me.

  • Force PowerShell version on remote session

    Hi, as the title suggest, I want to explicitly use PowerShell 2.0 to execute scripts and commands, why? Because SharePoint 2010 only supports PowerShell 2.0. So my problem:
    I have SharePoint 2010 installed on a Windows Server 2012 (with PowerShell 4.0 as default). When I execute a SharePoint PowerShell command on the server, it only works when I go to a PowerShell 2.0 console (powershell.exe
    -v 2). But when I am on another server and start a PowerShell 2.0 console, the remote session I create with e.g. Enter-PSSession is always PowerShell 4.0, the version of the host. This will prevent me from executing SharePoint commands remotely
    So my question is, is it possible in some way to force a specific version of PowerShell with a remote session?

    Hi TechPeepz,
    To start powershell 2.0 on remote session, please refer to the steps below:
    Server02 remote access Server01
    1. Run the cmdlet below on server01
    Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0
    2. Run the cmdlets below on server02
    $s = New-PSSession -ComputerName Server01 -ConfigurationName PS2
    Enter-PSSession -Session $s
    For more detailed information, please refer to this article:
    Starting the Windows PowerShell 2.0 Engine
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang

  • Restricting powershell version in script

    Stupid question probably, but just want to make sure.
    Does Set-StrictMode -Version 2.0 actually prevent the script from processing functionality that exists in Powershell 3 or 4 or does it just implement "strictMode" rules that existed in version 2?
    Thanks.

    No.
    If the objective is to make sure your script works in PS2, I recommend you test it in a system running PS2 (ONLY).
    Set-StrictMode instructs the parser to not do a bunch of 'nice' things for us including:
    If it comes across a variable that has not been initialized, it give it a value of zero instead of generating a terminating error.
    If it comes across a reference to non-existing property, it returns $null instead of generating a terminating error
    Now, these 'nice' things are nice and helpful most of the time. But sometimes they make debugging harder. 
    For example:
    $VMName = 'VM1','VM2','VM3'
    foreach ($VM in $VMName) {
    "Processing '$VM'"
    This returns output like:
    Processing 'VM1'
    Processing 'VM2'
    Processing 'VM3'
    Now, imagine that we made a typo like:
    $VMName = 'VM1','VM2','VM3'
    foreach ($VM in $VNName) {
    "Processing '$VM'"
    Can you spot the typo?
    All we can see at first glance, is that we have no output, and NO ERROR message:
    On second look you may notice $VMName has been misspelled in the foreach line. 
    However, if that was a several hundred line complex script block, you may spend hours or days trying to figure out why you're getting no output, while the error is simply a hard to spot typo. 
    The reason we got no error message is that PS did us a favor and ASSUMED we meant to declare $VNName as a new variable and assigned it an initial value of zero.
    Now, Set-StrictMode can help debugging by giving out errors when the parser comes across things like uninitialized variables or reference to object properties that don't exist. In our example:
    Set-StrictMode -Version 4
    $VMName = 'VM1','VM2','VM3'
    foreach ($VM in $VNName) {
    "Processing '$VM'"
    will return an error:
    The morale of the story is that Set-StrictMode is a scoped debugging tool, not to enforce script backward compatibility. 
    I'll let you lookup the difference between the different values you can select with the -Version parameter of Set-StrictMode..
    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________
    Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

  • Powershell versions by operating system

    Hi -
    Wondering if I can get a confirmation on the versions of PowerShell by Operating System Version.  What is the highest level of PoSH that can be ran on each Server O/S?
    Is the below accurate?
    Windows server 2012 R2 - PowerShell 4.0
    Windows server 2008 R2 - PowerShell 3.0
    Windows server 2003 SP2 - PowerShell 2.0

    Just to add to this, don't forget that many of the newer modules (e.g. NetAdapter) still require later operating systems. Just because you're running V4 on your Win7 desktop (or WS2008R2 server) doesn't mean you get access to the newer cmdlets.
    Don't retire TechNet! -
    (Don't give up yet - 12,830+ strong and growing)

  • Selecting Items From a List Box No Longer Works in Powershell Version 3.0

    I've noticed that the script in
    this powershell tip of the week no longer seems to fully work in Powershell V3. The selection dialog will pop up as expected, with all of the elments populated, but the selection is not stored in variable '$x'. Any idea what changed and how to get it to
    work?
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    $objForm = New-Object System.Windows.Forms.Form
    $objForm.Text = "Select a Computer"
    $objForm.Size = New-Object System.Drawing.Size(300,200)
    $objForm.StartPosition = "CenterScreen"
    $objForm.KeyPreview = $True
    $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
    {$x=$objListBox.SelectedItem;$objForm.Close()}})
    $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
    {$objForm.Close()}})
    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Size(75,120)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = "OK"
    $OKButton.Add_Click({$x=$objListBox.SelectedItem;$objForm.Close()})
    $objForm.Controls.Add($OKButton)
    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Size(150,120)
    $CancelButton.Size = New-Object System.Drawing.Size(75,23)
    $CancelButton.Text = "Cancel"
    $CancelButton.Add_Click({$objForm.Close()})
    $objForm.Controls.Add($CancelButton)
    $objLabel = New-Object System.Windows.Forms.Label
    $objLabel.Location = New-Object System.Drawing.Size(10,20)
    $objLabel.Size = New-Object System.Drawing.Size(280,20)
    $objLabel.Text = "Please select a computer:"
    $objForm.Controls.Add($objLabel)
    $objListBox = New-Object System.Windows.Forms.ListBox
    $objListBox.Location = New-Object System.Drawing.Size(10,40)
    $objListBox.Size = New-Object System.Drawing.Size(260,20)
    $objListBox.Height = 80
    [void] $objListBox.Items.Add("atl-dc-001")
    [void] $objListBox.Items.Add("atl-dc-002")
    [void] $objListBox.Items.Add("atl-dc-003")
    [void] $objListBox.Items.Add("atl-dc-004")
    [void] $objListBox.Items.Add("atl-dc-005")
    [void] $objListBox.Items.Add("atl-dc-006")
    [void] $objListBox.Items.Add("atl-dc-007")
    $objForm.Controls.Add($objListBox)
    $objForm.Topmost = $True
    $objForm.Add_Shown({$objForm.Activate()})
    [void] $objForm.ShowDialog()
    $x

    Hi,
    What is the value of $x?
    Make sure that you have copied the whole script, and whether it works on Powershell V2?
    Regards,
    Yan Li
    TechNet Subscriber Support
    If you are
    TechNet Subscription
    user and have any feedback on our support quality, please send your feedback
    here.
    Cataleya Li
    TechNet Community Support

  • How check Powershell Version ?

    Hi...all
    I installed SQL Server 2008 Dev edition on XP sp3.(It Installs WPS)
    I am very much new to PS..I started testing my Installation.
    For example, I typed Get-PS and press the Tab key , 
    the following cmdlets are appearing
    Get-PSDrive
    Get-PSProvider
    Get-PSSnapin
    But It suppose to show below list 
    ❑ Get-PSBreakpoint
    ❑ Get-PSCallStack
    ❑ Get-PSDrive
    ❑ Get-PSProvider
    ❑ Get-PSSession
    ❑ Get-PSSessionConfiguration
    ❑ Get-PSSnapin
    Why some other cmdlets are missing...Help me how to resolve and how check the Present version of WPS.
    Thanks in Advance
    SNIVAS

    I wish Thomas Lee was still participating here.
      - Larry
    I do Larry - from time to time. But I find the web so painful and slow to use I spend less time here than I used to spend in the old newsgroups. ANd sadly, Microsoft's latest OSs have killed my favourite NNTP client (it was IE based and they changed IE64
    to the point where it broke Turnpike). OH well
    Thomas Lee <[email protected]>

  • New Version of the Azure Active Directory Module and PowerShell 2.0

    Since the last upgrade of the Azure Active Directory Module for Windows PowerShell (64-bit version), we are no longer able to load it in an application targeting .NET Framework 3.5 SP1. The error message that we receive is:
    Could not load file or assembly 'file:///C:\Windows\system32\WindowsPowerShell\v1.0\Modules\MSOnline\Microsoft.Online.Administration.Automation.PSModule.dll' or one of its dependencies. This assembly is built by a runtime newer
    than the currently loaded runtime and cannot be loaded.
    Our application loads and uses the Azure AD PowerShell Module for Azure AD management. The previous version of the module available until September worked well, however, we cannot use the new version because it is built using the .NET Framework 4.0 runtime,
    and our application targets .NET Framework 3.5 SP1.
    The link for the old version of the module was removed, and since the EULA for the module restricts us from making the old version available on our web site, we need a solution that would enable us
    to load the module in our application because we cannot retarget the application to a newer Framework version. In particular,
    we need a link that our customers can use to download the old version of the module.
    Is there a URL to the old version of the Azure Active Directory Module that we can download the old version from? Can someone help?

    Hi Vladimir,
    Since I'm not familiar with AZure AD, to get the old version of Azure AD Module, I also recommend you can post in Azure AD forum for more effective support:
    http://social.msdn.microsoft.com/forums/azure/en-US/home?forum=WindowsAzureAD
    However, for the error you posted, as you said, this is related to .NET version.
    I found a similar error, which was solved by upgrading the Powershell version 3.0 on Server 2008 R2 sp1, which also need to update the .NET version on server.
    Active Directory Single sign-on Office 365 Powershell Error
    If there is anything else regarding the powershell, please feel free to post back.
    Best Regards,
    Anna Wang
    Anna, yep upgrading to version 3.0 simple solve the issue. But WMF 3.0 is not compatible with few things like
    SharePoint 2010, Exchange 2007 , SCCM etc.
    WMF 3.0 has the same .NET version so how about making a configuration file in version 2.0
    I am not really sure if Azure support this but its worth to make your configuration file to support .NET 4.0
    $PShome\PowerShell_ISE.CONFIG and $PSHOME\PowerShell.exe.config will be not existing.
    So you can make an entry in configuration to support .NET framework 4.0
    like shown below
    $config_text = @"
    <?xml version="1.0"?>
    <configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0.30319"/>
    <supportedRuntime version="v2.0.50727"/>
    </startup>
    </configuration>
    $config_text| Out-File $pshome\powershell.exe.config
    $config_text| Out-File $pshome\powershell_ise.exe.config
    Close PowerShell Console and open as administrator.
    Try loading the modules back and let me know.
    Regards Chen V [MCTS SharePoint 2010]

  • Issue creating Item Activated Events for a third party form Control in Windows Powershell

    I was asked at work to look into converting some of our VB.Net Applications to PowerShell. We use the
    QIOS dev Suite for some of the controls to make it more visually appealing. I have been testing to controls out and I can load and create forms with no issue in powershell but I'm stumped on the error I'm
    receiving when I add and ItemActivated event. I need to make it so when a user clicks on a given menu Item the form gets which menu item is clicked. 
    Below is the code to my test form.
    [VOID][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    [VOID][reflection.assembly]::LoadFile("C:\Code\Qios.DevSuite.Components.dll")
    [System.Windows.Forms.Application]::EnableVisualStyles()
    $form1 = New-Object 'System.Windows.Forms.Form'
    $Menu = New-Object 'Qios.DevSuite.Components.QCompositeControl'
    $item = New-Object 'Qios.DevSuite.Components.QCompositeMenuItem'
    $DOSOMETHING={Write-Host "DO SOMETHING"}
    # form1
    $form1.Controls.Add($Menu)
    $form1.ClientSize = '202, 262'
    $form1.Name = "form1"
    $form1.Text = "Form"
    $form1.add_Load($form1_Load)
    #MenuItem
    $Item.ItemName = "Test Item"
    $Item.Title = "Test Item"
    # Menu
    $Menu.Location = '13, 12'
    $Menu.Name = "panel1"
    $Menu.Size = '177, 238'
    $Menu.Items.Add($Item)
    $Menu.Add_ItemActivated($DOSOMETHING)
    $form1.ShowDialog()
    If someone could take a look and tell me what I'm doing wrong that would be great. If you need the dll file below is a link to my copy.

    I was able to get the attached code to work in windows 7 with powershell version 2. I have to see why it dosent like windows 8 and powershell version 4.
    Update: I just did powershell -version 2 in windows 8 and I was able to run the code. 
    [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    [void][reflection.assembly]::LoadFile("C:\Users\xAdmin\Desktop\Qios.DevSuite.Components.dll")
    $frmMain = New-Object 'System.Windows.Forms.Form'
    $ccMenu = New-Object 'Qios.DevSuite.Components.QCompositeControl'
    $ccitem = New-Object 'Qios.DevSuite.Components.QCompositeMenuItem'
    $Function = {
    param ($sender, $e)
    [System.Windows.Forms.MessageBox]::Show($e.Item.ItemName)
    $frmMain.Controls.Add($ccMenu)
    $frmMain.ClientSize = '202, 262'
    $frmMain.Name = "form1"
    $frmMain.Text = "Form"
    $frmMain.add_Load($form1_Load)
    $ccMenu.Location = '13, 12'
    $ccMenu.Name = "panel1"
    $ccMenu.Size = '177, 238'
    $ccMenu.Items.Add($ccitem) | Out-Null
    $ccMenu.Add_ItemActivated($Function)
    $ccitem.ItemName = "Test Item"
    $ccitem.Title = "Test Item"
    $ccitem.Configuration.StretchHorizontal = $true
    $frmMain.ShowDialog()

  • How can I use PowerShell to Remove "Ghost" (Old Hidden) VMware Network Adapters in Windows 7?

    We recently upgrade the virtual hardware of some of our VMware VM's running Windows 7. One side-effect is that in Windows on these machines, an instance of the NIC from the previous version of virtual hardware remains, as a hidden
    device. This can be easily found manually on a machine by enabling Device manager to show hidden devices (registry and a menu option - View...Show Hidden Devices). You can then just right-click on the device in question and uninstall.
    The problem here, like in so many other tasks, is that you may have multiple instances, on multiple machines. We had just that, and in scouring the internet for a PowerShell only script to resolve the issue, I could not find one. Therefore, I've written
    my own.
    This exact script is only seeking out VMware "VMXNET3" nic cards, but could be easily adapted to find Ghost NIC's for a different vendor using my example. There are also some commented lines left in to aid you as an example of how you can
    test the various queries in your own environment, on a test machine, before a full-blown deployment. 
    NOTE: Please try this out (at your own risk - I am not responsible for how this works out for you), and please vote for my answer to this dilemma if this helped you. I'd appreciate it after all of the sweat the script took to crank out.
    Thanks!
    P.S. This script, of course, requires that Powershell is installed and enabled on the target computer. It then must be run as System - In our environment it is being remotely pushed through a software delivery systems, which runs this scrpt
    as system.
    THE SCRIPT:
    CLS
    #Querying WMI for Ghost NICs and Returning Criteria...
     Write-Host "VMware Ghost NIC Remover" -Foreground GREEN
     Write-Host "Author: Octavio Serpa AKA Octavio-Admin"
     Write-Host "Copyright Octavio Serpa - Octavio-Admin - 2014"
     Write-Host ""
     Write-Host "Checking Powershell Version" -Foreground Yellow
     $host.version
     Write-Host ""
     Write-Host "Searching for Ghost NIC's" -Foreground Yellow
     $Ghosts = gwmi win32_NetworkAdapter | ?{$_.Description -like "vm*" -and $_.Installed -like "True" -and $_.MACAddress -eq $null}
     $Ghosts | Select-Object Name,DeviceID
     If ($Ghosts -NE $NULL)
      Write-Host "One or more ghost NIC'S do exist on this machine. Script will continue..." -foreground RED
      Write-Host ""    
      else
      Write-Host "No ghost NIC's Found :) - Exiting..." -Foreground Green
      Write-Host ""    
      EXIT 0
    #Using Criteria to Obtain the GUID of each Ghost NIC
     Write-Host "Getting NIC Variables" -Foreground Yellow
     foreach ($_ in $Ghosts) {
      $DID = $_.DeviceID
      If ($DID -NE $NULL)
      Write-Host "The NIC DID: $DID"
      else
      Write-Host "$DID is NULL - Exiting..."
      EXIT 666
      if($DID -NOTLIKE "1*")
       Write-Host "Adding additional 0 to registry lookup since the DID is just one character..." - foreground yellow
       Write-Host "" 
       $NICREG = Get-ItemProperty "hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\000$DID"
      ELSE
       $NICREG = Get-ItemProperty "hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\00$DID"
      $GUID = $NICREG.NetCfgInstanceId
      Write-Host "The NIC GUID: $GUID"
                    $PNPDID = $NICREG.DeviceInstanceID
      $PNPDID = $PNPDID.Trimstart("PCI\VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01\")
      Write-Host "The truncated PNPDevice ID is $PNPDID"
      Write-Host ""
      Write-Host "Searching for Registry Keys that match NIC GUID: $GUID" -Foreground Yellow
      $NICREGPATH = @(1..50)
      foreach ($_ in $NICREGPATH)
       $TESTREG = Test-Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\$_" -Verbose
       if($TESTREG -EQ $FALSE)
        #Write-Host ""
        #Write-Host "FALSE: HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\$_ DOES NOT EXIST" -Foreground RED     
        ELSE
        #Write-Host "True - NIC $_ Exists" -Foreground Green
        $NICID = $_    
        $SubPath1 = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\'+$NICID
        #Write-Host "The Sub-Key Path To Query = $SubPath1"
        $SubPath2 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\NetworkCards\'+$NICID
        #Write-Host "The Sub-Key Path To Query = $SubPath2"
        $NICProperties = Get-ItemProperty $SubPath1
        #$NICProperties
        $Match = $NICProperties.ServiceName    
        #$Match
        foreach ($_ in $Match) {
        #Write-Host "The NIC GUID found in this registry key is: $_" -Foreground Yellow
        #Write-Host ""
        if($_ -NE $GUID)
        #Write-Host "NO MATCH - THIS NIC HAS NOT BEEN TOUCHED" -Foreground GREEN
                                    #Write-Host ""
        ELSE
        Write-Host "MATCH - Registry Entries for this NIC will be DELETED" -Foreground RED
        Remove-Item $SubPath1 -Recurse  -ErrorAction SilentlyContinue
        Remove-Item $SubPath2 -Recurse  -ErrorAction SilentlyContinue
        $CCS = @("ControlSet001", "ControlSet002")
        foreach ($_ in $CCS) {
         $CCS = $_
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Services\'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose 
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Services\Tcpip\Parameters\Adapters\'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\DeviceClasses\{ad498944-762f-11d0-8dcb-00c04fc3358c}\##?#PCI#VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01#$PNPDID#{ad498944-762f-11d0-8dcb-00c04fc3358c}\#'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\JNPRNA\Parameters\Adapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\NetBT\Parameters\Interfaces\Tcpip_' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Psched\Parameters\NdisAdapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Tcpip\Parameters\Adapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Tcpip\Parameters\DNSRegisteredAdapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Tcpip\Parameters\Interfaces\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\WfpLwf\Parameters\NdisAdapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
                                             if($DID -NOTLIKE
    "1*")
                  $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\000' + $DID
                             Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
           ELSE
           $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\00' + $DID
           Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Enum\PCI\VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01\' + $PNPDID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
    #This is our Success check at the end
     Write-Host ""
     Write-Host "Searching for any remaining Ghost NICs:" -Foreground Yellow
              $Ghosts = gwmi win32_NetworkAdapter | ?{$_.Description -like "vm*" -and $_.Installed -like "True" -and $_.MACAddress -eq $null}
     $Ghosts | Select-Object Name,DeviceID
      If ($Ghosts -NE $NULL)
      Write-Host "There is still at least one ghost NIC present. The remover script may not be functioning correctly. Please contact Octavio-Admin on Microsoft Technet Forums with any questions" -foreground RED
      Write-Host ""
      EXIT 666
      else
      Write-Host "No ghost NIC's Found :) - Exiting..." -Foreground Green
      Write-Host ""    
      EXIT 0

    THE SCRIPT:
    CLS
    #Querying WMI for Ghost NICs and Returning Criteria...
    Write-Host "VMware Ghost NIC Remover" -Foreground GREEN
    Write-Host "Author: Octavio Serpa AKA Octavio-Admin"
    Write-Host "Copyright Octavio Serpa - Octavio-Admin - 2014"
    Write-Host ""
    Write-Host "Checking Powershell Version" -Foreground Yellow
    $host.version
    Write-Host ""
    Write-Host "Searching for Ghost NIC's" -Foreground Yellow
    $Ghosts = gwmi win32_NetworkAdapter | ?{$_.Description -like "vm*" -and $_.Installed -like "True" -and $_.MACAddress -eq $null}
    $Ghosts | Select-Object Name,DeviceID
    If ($Ghosts -NE $NULL)
      Write-Host "One or more ghost NIC'S do exist on this machine. Script will continue..." -foreground RED
      Write-Host ""   
      else
      Write-Host "No ghost NIC's Found :) - Exiting..." -Foreground Green
      Write-Host ""   
      EXIT 0
    #Using Criteria to Obtain the GUID of each Ghost NIC
    Write-Host "Getting NIC Variables" -Foreground Yellow
    foreach ($_ in $Ghosts) {
      $DID = $_.DeviceID
      If ($DID -NE $NULL)
      Write-Host "The NIC DID: $DID"
      else
      Write-Host "$DID is NULL - Exiting..."
      EXIT 666
      if($DID -NOTLIKE "1*")
       Write-Host "Adding additional 0 to registry lookup since the DID is just one character..." - foreground yellow
       Write-Host ""
       $NICREG = Get-ItemProperty "hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\000$DID"
      ELSE
       $NICREG = Get-ItemProperty "hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\00$DID"
      $GUID = $NICREG.NetCfgInstanceId
      Write-Host "The NIC GUID: $GUID"
                    $PNPDID = $NICREG.DeviceInstanceID
      $PNPDID = $PNPDID.Trimstart("PCI\VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01\")
      Write-Host "The truncated PNPDevice ID is $PNPDID"
      Write-Host ""
      Write-Host "Searching for Registry Keys that match NIC GUID: $GUID" -Foreground Yellow
      $NICREGPATH = @(1..50)
      foreach ($_ in $NICREGPATH)
       $TESTREG = Test-Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\$_" -Verbose
       if($TESTREG -EQ $FALSE)
        #Write-Host ""
        #Write-Host "FALSE: HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\$_ DOES NOT EXIST" -Foreground RED    
        ELSE
        #Write-Host "True - NIC $_ Exists" -Foreground Green
        $NICID = $_   
        $SubPath1 = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\'+$NICID
        #Write-Host "The Sub-Key Path To Query = $SubPath1"
        $SubPath2 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\NetworkCards\'+$NICID
        #Write-Host "The Sub-Key Path To Query = $SubPath2"
        $NICProperties = Get-ItemProperty $SubPath1
        #$NICProperties
        $Match = $NICProperties.ServiceName   
        #$Match
        foreach ($_ in $Match) {
        #Write-Host "The NIC GUID found in this registry key is: $_" -Foreground Yellow
        #Write-Host ""
        if($_ -NE $GUID)
        #Write-Host "NO MATCH - THIS NIC HAS NOT BEEN TOUCHED" -Foreground GREEN
                                    #Write-Host ""
        ELSE
        Write-Host "MATCH - Registry Entries for this NIC will be DELETED" -Foreground RED
        Remove-Item $SubPath1 -Recurse  -ErrorAction SilentlyContinue
        Remove-Item $SubPath2 -Recurse  -ErrorAction SilentlyContinue
        $CCS = @("ControlSet001", "ControlSet002")
        foreach ($_ in $CCS) {
         $CCS = $_
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Services\'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Services\Tcpip\Parameters\Adapters\'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\DeviceClasses\{ad498944-762f-11d0-8dcb-00c04fc3358c}\##?#PCI#VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01#$PNPDID#{ad498944-762f-11d0-8dcb-00c04fc3358c}\#'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\JNPRNA\Parameters\Adapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\NetBT\Parameters\Interfaces\Tcpip_' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Psched\Parameters\NdisAdapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Tcpip\Parameters\Adapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Tcpip\Parameters\DNSRegisteredAdapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Tcpip\Parameters\Interfaces\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\WfpLwf\Parameters\NdisAdapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
                                             if($DID -NOTLIKE
    "1*")
                  $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\000' + $DID
                             Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
           ELSE
           $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\00' + $DID
           Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Enum\PCI\VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01\' + $PNPDID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
    #This is our Success check at the end
    Write-Host ""
    Write-Host "Searching for any remaining Ghost NICs:" -Foreground Yellow
              $Ghosts = gwmi win32_NetworkAdapter | ?{$_.Description -like "vm*" -and $_.Installed -like "True" -and $_.MACAddress -eq $null}
    $Ghosts | Select-Object Name,DeviceID
      If ($Ghosts -NE $NULL)
    Write-Host "There is still at least one ghost NIC present. The remover script may not be functioning correctly. Please contact Octavio-Admin on Microsoft Technet Forums with any questions" -foreground RED
      Write-Host ""
      EXIT 666
      else
      Write-Host "No ghost NIC's Found :) - Exiting..." -Foreground Green
      Write-Host ""   
      EXIT 0
    Hello Octavio,
    I'm having similar issues with azure VMs (windows server 2008 and 2012). I noticed that the name of the network adapter changes every time the servers are turned off and then on.
    For example every time I perform that action on each VM, the network adapter became to "Microsoft Hyper-V Network Adapter #3" (and then #4, #5, etc).
    I found in to many forums that to resolve that is needed to remove Hidden (Ghost) Network Adapters and most of the people is doing that manually from the device manager (right click on the hidden network adapter and select uninstall).
    Then I found this script created by you and made some changes to find Description -like "Microsoft Hyper-V Network*".
    It seems to find the adapters and also remove them (based on the script results). But if I go to the device manager after restarting the server, all hidden (ghost) adapters are still there (for example Microsoft Hyper-V Network Adapter
    #2, Microsoft Hyper-V Network Adapter #3, Microsoft Hyper-V Network Adapter #4, Microsoft Hyper-V Network Adapter #n).
    The only thing I noticed after running the script is that, in the Control Panel -> Network and Sharing Center, the name of the adapter has no # (Now is shown as “Ethernet” and before as “Ethernet #”)
    This is my script, could you please take a look and tell me if there is something wrong o missing?
    CLS
    #Querying WMI for Ghost NICs and Returning Criteria...
    Write-Host "VMware Ghost NIC Remover" -Foreground GREEN
    Write-Host "Author: Octavio Serpa AKA Octavio-Admin"
    Write-Host "Copyright Octavio Serpa - Octavio-Admin - 2014"
    Write-Host ""
    Write-Host "Checking Powershell Version" -Foreground Yellow
    $host.version
    Write-Host ""
    Write-Host "Searching for Ghost NIC's" -Foreground Yellow
    $Ghosts = gwmi win32_NetworkAdapter | ?{$_.Description -like "Microsoft Hyper-V Network*" -and $_.Installed -like "True" -and $_.MACAddress -eq $null}
    $Ghosts | Select-Object Name,DeviceID
    If ($Ghosts -NE $NULL)
      Write-Host "One or more ghost NIC'S do exist on this machine. Script will continue..." -foreground RED
      Write-Host ""    
      else
      Write-Host "No ghost NIC's Found :) - Exiting..." -Foreground Green
      Write-Host ""    
      EXIT 0
    #Using Criteria to Obtain the GUID of each Ghost NIC
    Write-Host "Getting NIC Variables" -Foreground Yellow
    foreach ($_ in $Ghosts) {
      $DID = $_.DeviceID
      If ($DID -NE $NULL)
      Write-Host "The NIC DID: $DID"
      else
      Write-Host "$DID is NULL - Exiting..."
      EXIT 666
      if($DID -NOTLIKE "1*")
       Write-Host "Adding additional 0 to registry lookup since the DID is just one character..." - foreground yellow
       Write-Host "" 
       $NICREG = Get-ItemProperty "hklm:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\000$DID"
      ELSE
       $NICREG = Get-ItemProperty "hklm:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\00$DID"
      $GUID = $NICREG.NetCfgInstanceId
      Write-Host "The NIC GUID: $GUID"
                    $PNPDID = $NICREG.DeviceInstanceID
      $PNPDID = $PNPDID.Trimstart("PCI\VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01\")
      Write-Host "The truncated PNPDevice ID is $PNPDID"
      Write-Host ""
      Write-Host "Searching for Registry Keys that match NIC GUID: $GUID" -Foreground Yellow
      $NICREGPATH = @(1..50)
      foreach ($_ in $NICREGPATH)
       $TESTREG = Test-Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\$_" -Verbose
       if($TESTREG -EQ $FALSE)
        #Write-Host ""
        #Write-Host "FALSE: HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\$_ DOES NOT EXIST" -Foreground RED     
        ELSE
        #Write-Host "True - NIC $_ Exists" -Foreground Green
        $NICID = $_   
        $SubPath1 = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\'+$NICID
        #Write-Host "The Sub-Key Path To Query = $SubPath1"
        $SubPath2 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\NetworkCards\'+$NICID
        #Write-Host "The Sub-Key Path To Query = $SubPath2"
        $NICProperties = Get-ItemProperty $SubPath1
        #$NICProperties
        $Match = $NICProperties.ServiceName    
        #$Match
        foreach ($_ in $Match) {
        #Write-Host "The NIC GUID found in this registry key is: $_" -Foreground Yellow
        #Write-Host ""
        if($_ -NE $GUID)
        #Write-Host "NO MATCH - THIS NIC HAS NOT BEEN TOUCHED" -Foreground GREEN
                                    #Write-Host ""
        ELSE
        Write-Host "MATCH - Registry Entries for this NIC will be DELETED" -Foreground RED
        Remove-Item $SubPath1 -Recurse  -ErrorAction SilentlyContinue
        Remove-Item $SubPath2 -Recurse  -ErrorAction SilentlyContinue
        $CCS = @("ControlSet001", "ControlSet002")
        foreach ($_ in $CCS) {
         $CCS = $_
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Services\'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose 
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Services\Tcpip\Parameters\Adapters\'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\DeviceClasses\{ad498944-762f-11d0-8dcb-00c04fc3358c}\##?#PCI#VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01#$PNPDID#{ad498944-762f-11d0-8dcb-00c04fc3358c}\#'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\'+$GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\JNPRNA\Parameters\Adapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\NetBT\Parameters\Interfaces\Tcpip_' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Psched\Parameters\NdisAdapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Tcpip\Parameters\Adapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Tcpip\Parameters\DNSRegisteredAdapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\Tcpip\Parameters\Interfaces\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\services\WfpLwf\Parameters\NdisAdapters\' + $GUID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
                                             if($DID -NOTLIKE "1*")
                  $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\000' + $DID
                             Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
           ELSE
           $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\00' + $DID
           Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
         $reg1 = 'HKLM:\SYSTEM\' + $CCS + '\Enum\PCI\VEN_15AD&DEV_07B0&SUBSYS_07B015AD&REV_01\' + $PNPDID
         Remove-Item $reg1 -Recurse  -ErrorAction SilentlyContinue -verbose
    #This is our Success check at the end
    Write-Host ""
    Write-Host "Searching for any remaining Ghost NICs:" -Foreground Yellow
              $Ghosts = gwmi win32_NetworkAdapter | ?{$_.Description -like "Microsoft Hyper-V Network*" -and $_.Installed -like "True" -and $_.MACAddress -eq $null}
    $Ghosts | Select-Object Name,DeviceID
      If ($Ghosts -NE $NULL)
    Write-Host "There is still at least one ghost NIC present. The remover script may not be functioning correctly. Please contact Octavio-Admin on Microsoft Technet Forums with any questions" -foreground RED
      Write-Host ""
      EXIT 666
      else
      Write-Host "No ghost NIC's Found :) - Exiting..." -Foreground Green
      Write-Host ""    
      EXIT 0

  • Backupeventlog not working for remote system in PowerShell

    I have the following code snippet that works if I specify localhost or the name of the local computer, but does not work if set to a remote server. I am running the script as Administrator using my Domain Admin account. Both local and remote systems
    are Windows Server 2012 and in the same domain. PowerShell version = 3.0.
    Param(
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [ValidateScript({Test-Connection $_ })]
    [String]
    $Server,
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [String]
    $LogFileName,
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [ValidateScript({Test-Path $_ -PathType 'Container'})]
    [String]
    $OutputFolder
    $EventLog = Get-WmiObject win32_nteventlogfile -ComputerName $Server -Filter "LogFileName = '$LogFileName'" -ErrorAction SilentlyContinue -ErrorVariable $ResultError
    If ($ResultError)
    Write-Host "ERROR: unable to event logs from $Server."
    } Else {
    Write-Host "Backing $Server."
    $EventLog.backupeventlog("$OutputFolder\$Server.evtx")

    After spending some more time troubleshooting this and doing some more research I found the link below. I found it strange the hoops the author went through to handle event logs on remote systems until I realized that the path for "backupeventlog"
    is relative to the remote system, not the system running the script. So I checked the other systems and found that the event log backups had been created. This would explain the returnvalue of 80. What's worse is that the path for "backupeventlog"
    can't be a UNC -- I tried, it didn't work.
    Back Up Your Event Logs with a Windows PowerShell Script
    https://technet.microsoft.com/en-ca/magazine/2009.07.heyscriptingguy.aspx
    I decided to re-read Microsoft's documentation and found the magical text that I had over-looked:
    BackupEventlog method of the Win32_NTEventlogFile class
    https://msdn.microsoft.com/en-us/library/aa384808(v=vs.85).aspx
    In addition, you must make backups to the local computer; you cannot save a backup of the event logs on Computer A to Computer B. Backups are implemented by using the LocalSystem account, which does not have the network credentials necessary to access remote
    computers. If you want to save backups to a central repository, modify the script to first perform the backup, and then move the backup file to the central repository.
    jrv:
    I would mark your post of Wednesday, March 04, 2015 9:45 PM as helpful if this option were available. Your comment got me to dig into this deeper and discover
    the root cause.
    Thanks.

  • The Command Get-ADUser -Identity username -Properties * No Longer Works Due to a Bug in PowerShell 4 and Win8-1 Pro

    The 'Command Get-ADUser -Identity <username> -Properties *' No Longer Works Due to a Bug in PowerShell 4 and Win8-1 Pro
    It produces the following error:
    Get-ADUser : One or more properties are invalid.
    Parameter name: msDS-AssignedAuthNPolicy
    At line:1 char:1
    + Get-ADUser -Identity ********** -Properties *
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (**********:ADUser) [Get-ADUser], ArgumentException
        + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
    This is already documented in these forums:
    1. http://social.technet.microsoft.com/Forums/systemcenter/en-US/1bf9568e-6adc-495d-a37c-48877f86985a/powershell-40-and-the-activedirectory-ps-module?forum=w81previtpro
    2. https://connect.microsoft.com/PowerShell/feedback/details/806452/windows-8-1-powershell-4-0-get-adcomputer-properties-bug
    Unfortunately, in typical style, Microsoft have archived number 1 without bothering to respond with advice.  Can someone in Microsoft please advise your customers here if this is being investigated and of any available workaround or fix ?
    -- huddie "If you're not seeking help or offering it, you probably shouldn't be here."

    Did you consider using one of the "workarounds" below to run an existing version of the AD Module for PowerShell under a specific PowerShell version:
    a. #require -version 3.0    (in ps1 script)
    b. powershell -version 3.0
    Thank you for sharing with us if this helps.
    Desmond, did you miss my reply below ?  I still haven't heard back from you:
    >> "Desmond,
    >> 
    >> Thanks for your quick response.
    >> 
    >> I'm running this just as a command, not in a script:
    >> 
    >> Get-ADUser -Identity <username> -Properties *
    >> 
    >> When I try to run powershell
    -version 3.0 first, then run the above command, it still fails with the same error.  When I then run Get-Host,
    the version still shows as 4.0 so maybe there's more I need to do to launch a 3.0 host.  Anyway, from what I've read it seems your command is more aimed at script compatibility.
    >> 
    >> Can you help ?"
    -- huddie "If you're not seeking help or offering it, you probably shouldn't be here."

Maybe you are looking for