Command/Powershell script to reset a network adapter

You can use WMI from within PowerShell to accomplish this. Assuming there is a network adapter who’s device name has Wireless in it, the series of commands might look something like the following: $adaptor = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like “*Wireless*”} $adaptor.Disable() $adaptor.Enable() Remember, if you’re running this with Window’s Vista, you may … Read more

Is there a way to make certain functions “private” in a PowerShell script?

In fact, if you call a .ps1 file, by default any functions and variables declared within it are scoped privately within the script (this is referred to as “script scope”). Since you’re seeing both functions defined globally, I infer that you’re dot-sourcing SvcTest.ps1, i.e. invoking it like this PS> . <path>\SvcTest.ps1 rather than calling it … Read more

PowerShell Add-WindowsFeature unrecognized

This is probably because the PowerShell script is being launched from a 32 bit instance of PowerShell. The ServerManager commands are only available from 64 bit version of PowerShell. See: Can’t access ServerManager module via PowerShell –Edit – To add to jbsmith’s comments— Extra things to try: When you ran the Get-Command cmdlt: gcm | … Read more

Get target of shortcut (.lnk) file with powershell

You have made an error in the property; as wOxxOm suggests, you should be using TargetPath rather than Target: $sh = New-Object -ComObject WScript.Shell $target = $sh.CreateShortcut(‘<full-path-to-shortcut>’).TargetPath Google and MSDN were indeed helpful here; additionally, piping objects to Get-Member can often be useful and educational. This question also shows how to manipulate shortcuts using PowerShell, … Read more

Powershell: Get-Item vs Get-ChildItem

Get-Item Gets the item at the specified location. Get-Item .\foo # returns the item foo Get-ChildItem Gets the items and child items in one or more specified locations. Get-ChildItem .\foo # returns all of the children within foo note: Get-ChildItem can also recurse into the child directories Get-ChildItem .\foo -Recurse # returns all of the … Read more

How can I start a background job in Powershell that outlives it’s parent?

If you use Start-Process, you create a new child process that has your powershell session as its parent process. If you kill the powershell parent process that starts this, the new process will be orphaned and keep running. It will, however, not survive if you kill the parent’s process tree Start-Process -FilePath notepad.exe Powershell cannot … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)