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

How to strip illegal characters before trying to save filenames?

Casting the character array to System.String actually seems to join the array elements with spaces, meaning that [string][System.IO.Path]::GetInvalidFileNameChars() does the same as [System.IO.Path]::GetInvalidFileNameChars() -join ‘ ‘ when you actually want [System.IO.Path]::GetInvalidFileNameChars() -join ” As @mjolinor mentioned (+1), this is caused by the output field separator ($OFS). Evidence: PS C:\> [RegEx]::Escape([string][IO.Path]::GetInvalidFileNameChars()) “\ \ \|\ \ ☺\ … Read more

How can I launch powershell.exe with the “default” colours from the PowerShell shortcut?

Edit your profile script (pointed to by $profile) and set the desired colors yourself: # set regular console colors [console]::backgroundcolor = “darkmagenta” [console]::foregroundcolor = “darkyellow” # set special colors $p = $host.privatedata $p.ErrorForegroundColor = “Red” $p.ErrorBackgroundColor = “Black” $p.WarningForegroundColor = “Yellow” $p.WarningBackgroundColor = “Black” $p.DebugForegroundColor = “Yellow” $p.DebugBackgroundColor = “Black” $p.VerboseForegroundColor = “Yellow” $p.VerboseBackgroundColor = … Read more

Basic Powershell – batch convert Word Docx to PDF

This will work for doc as well as docx files. $documents_path=”c:\doc2pdf” $word_app = New-Object -ComObject Word.Application # This filter will find .doc as well as .docx documents Get-ChildItem -Path $documents_path -Filter *.doc? | ForEach-Object { $document = $word_app.Documents.Open($_.FullName) $pdf_filename = “$($_.DirectoryName)\$($_.BaseName).pdf” $document.SaveAs([ref] $pdf_filename, [ref] 17) $document.Close() } $word_app.Quit()

Powershell – Reboot and Continue Script

There is a great article on TechNet from the Hey, Scripting Guy series that goes over a situation very similar to what you are describing: Renaming a computer and resuming the script after reboot. The magic is to use the new workflows that are part of version 3: workflow Rename-And-Reboot { param ([string]$Name) Rename-Computer -NewName … Read more

Powershell: Scheduled Task with Daily Trigger and Repetition Interval

While the PowerShell interface for scheduled task triggers is limited, it turns out if you set the RepetitionDuration to [System.TimeSpan]::MaxValue, it results in a duration of “Indefinitely”. $trigger = New-ScheduledTaskTrigger ` -Once ` -At (Get-Date) ` -RepetitionInterval (New-TimeSpan -Minutes 5) ` -RepetitionDuration ([System.TimeSpan]::MaxValue) Tested on Windows Server 2012 R2 (PowerShell 4.0)

How to import custom PowerShell module into the remote session?

There were some great comments to the question, and I’ve spent some time investigating various ways to approach the problem. To begin with, what I’ve initially asked for is not possible. I mean, if you go the module way, then the module should be physically present on a target machine to be able to Import-Module … Read more

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