if user installs windows in his native language(not english) he can access files using localized paths ie. insted C:\Users\UserName\Desktop he can access Desktop using C:\LocalizedUsersName\LocalizedDesktopName Is there any Powershell command which can convert/translate local version of the Path to the English version?
There is nothing specifically for a path, yet, basically, along the same lines as you'd do this for other strings you are working with. See the discussions, examples, and answers below.
International Settings Cmdlets in Windows PowerShell
Using the Microsoft Translator API from PowerShell
Localization and PowerShell
plattsoft_PSUICultureExample
Forcing PowerShell errors output in English on localized systems
You can change the pipeline thread's CurrrentUICulture like so:
[Threading.Thread]::CurrentThread.CurrentUICulture = 'fr-FR'; Get-Help
Get-Process
I'm on an English system but before I executed the line above, I
updated help like so: Update-Help -UICulture fr-FR
$ENUS="[Threading.Thread]::CurrentThread.CurrentUICulture = 'en-US'"
then invoke-expression $ENUS; Get-Help Get-Process "invoke-expression
$ENUS;" is little shorter if you need to run many commands
Related
I have been googling and trying different options but I didn't really find anything useful or that worked.
My question is how to set default open location for windows PowerShell, I want it to always open c:/programming/ folder when I start it from like start menu, instead what it opens now.
I'm using windows 10.
Thnx for help
the usual way to tell PoSh where to start up at is to add a Set-Location line to one of your powershell profile files. i added ...
Set-Location D:\Data\Scripts
... to my CurrentUserCurrentHost file. you can learn more about profiles with ...
Get-Help about_Profiles
you can find your version of the profile i used thus ...
$profile |
Select-Object -Property *
please note that none of these files exist by default. you will likely need to make one. if you do be sure it is a plain text file, not a .doc file! [grin]
I have written a script for my MySQL database with the Powershell ISE, which creates a backup for me with the help of the MySQL dump tool.
When I run the script in the PowerShell ISE, everything works. If I execute the same script now in the normal PowerShell, he does not show me the German umlauts correctly.
Here is my script:
# delete everything older than 30 days
foreach ($ordner in (ls D:\Backup -Depth 0))
{
if ($ordner.LastWriteTime.Date -lt (Get-Date).AddDays(-30).Date)
{
rm -Recurse ("D:\Backup\"+ $ordner.Name)
}
}
mkdir ("D:\Backup\" + (Get-Date -Format "yyyy_MM_dd") + "\Datenbank")
C:\xampp\mysql\bin\mysqldump.exe -uroot --default-character-set=latin1 --opt MY_DATABASE > ("D:\Backup\"+(Get-Date -Format "yyyy_MM_dd") + "\Datenbank\backup.sql")
However, I need the normal PowerShell for the automated execution and the script.
How can I fix the problem that the German umlauts are displayed in the normal PowerShell correctly?
The Windows PowerShell ISE differs from regular (conhost.exe) PowerShell console windows in that it interprets the output from external programs (such as mysqldump.exe) as encoded based on the active ANSI code page (e.g., Windows-1252 on US-English systems) - which is what --default-character-set=latin1 in your command requests.
Note: The PowerShell ISE is no longer actively developed and there are reasons not to use it (bottom section), notably not being able to run PowerShell [Core] 6+. The actively developed editor that offers the best PowerShell development experience, across platforms, is Visual Studio Code, combined with its PowerShell extension.
By contrast, regular PowerShell console windows default to the active OEM code page (e.g., 437 on US-English systems).
It is the encoding reported by [console]::OutputEncoding that determines how PowerShell interprets the output from external programs (though for mere display output that may not matter).
Therefore, you have two options:
Adjust the --default-character-set option to match the code page reported by [console]::OutputEncoding - assuming MYSQL supports it (this documentation suggests that the US-English OEM code page 437 is not supported, for instance).
Adjust [console]::OutputEncoding to (temporarily) match the specified --default-character-set option:
[console]::OutputEncoding = [System.Text.Encoding]::GetEncoding(1252)
In general, it is (Get-Culture).TextInfo.ANSICodePage / (Get-Culture).TextInfo.OEMCodePage that reports the a given system's active ANSI / OEM code page number.
I am writing a Powershell script to make a raw copy of a drive and I have been unable to find a way to complete this.
On Linux, I would use 'dd' to perform this copy.
There are a handful of tools that can do this on Windows but none that I can control directly from the command line. (All have GUI interfaces)
Is there a method to make a physical copy of a drive through Powershell?
Thanks.
I've been trying to do this for a while myself and I finally found a good answer.
Git for windows ships with the whole set of GNU core utilities (updated vs what you can find separately) including dd!
Just install Git for Windows or extract the portable version, from there inside of the install directory in git\usr\bin\ you will find the binaries for all of the GNU utils including dd (tested working)
Some further notes on usage in windows since \dev\sda\ isn't a thing:
$DiskDrives = Gwmi Win32_diskdrive | select DeviceID,BytesPerSector,Index,Caption,InterfaceType,Size,TotalSectors,SerialNumber | Out-GridView -OutputMode Multiple -Title 'Select Source Drive(s)'
$BaseOutputPath = 'D:\'
$DiskDrives | %{
. ('C:\Program Files\Git\usr\bin\dd.exe if={0} of={1} bs={2}' -f $_.DeviceID,(-join($BaseOutputPath,(-
join($Env:ComputerName,$_.Index)),'.img')),$_.BytesPerSector)
}
The included filename logic is just a placeholder, you can replace that parenthetical with a call to Read-Host if you want it to prompt you for the filename/path.
It is a bit annoying but you really do have to use WMI as the values returned by Get-Disk don't seem to work.
You might already know that cygwin on Windows supports some Linux commands including dd. I have used it on several occasions to copy disks and load ISOs to USB and it works perfectly.
Windows 10 comes with linux now. Windows Subsystem for Linux. You can enable it as a feature. You can even get WSL 2 with the real kernel in 1903 & 1909: https://devblogs.microsoft.com/commandline/whats-new-in-the-windows-subsystem-for-linux-september-2020/
Get-CimInstance -ClassName Win32_DiskDrive | Format-List -Property DeviceID,BytesPerSector,Index,Caption,InterfaceType,Size,TotalSectors,SerialNumber
Following up #Chirishman answer, for Powershell 7.2, The Gwmi may missing from the powershell.
The alternative command to get the DeviceId and other info is available as above.
Then you can use dd if={DeviceId} of=<target_file>.
There is script command on GNU/Linux machine which allows to capture all command line activity into a file . This is really helpful tool especially when we learn something new and we want to save the commands and their output for future reference.
I am currently learning the Git on Windows PowerShell terminal and I wanted to capture all the commands and their output in a file for future reference.
Is there any way/command do achieve it on Windows PowerShell?
Try with Start-Transcript and Stop-Transcript cmdlet.
You can also use Start-Transcript for ISE Editor module because these CmdLet don't work natively in ISE.
It exists standard CmdLets : Start-Transcript and Stop-Transcript.
You'll find more informations about these CmdLet in the associeted TechNet documentation.
What is the powershell equivalent of 'less'?
I see 'more', but it lacks some of the features I rely on (e.g. searching through the file)
I seek a pager (equivalent of 'less') which allows searching (match or ignore case), multiple files at once, etc.
Some of our servers run windows 2008 and I lack admin privileges to install cygwin
I had heard windows 2008, MSFT got their act together and provided some easy-for-admins tools.
Update:
I should give some context:
I know little about power shell
New servers have 2008 on them
While I affection for many tools of yore, the dos prompt is not one of them
I was hoping that Powershell had the equivalent of grep,ls,less, xargs, et
I understood that powershell gave us those tools
I fired off my question quickly.
thanks
It reads like you know you can do this:
gc logfile.log | more
(GC is an alias for Get-Content).
You may be able to do the filtering etc.. with this more information can be found by running these commands:
Get-Help Get-Content Get-Help
Get-Content -Examples
(Get-Help gc would work fine as well).
And the bits you may be interested in are limit\filter etc...
Get-Help gc -Parameter * | more
I just use the GOW version of less, works fine.
I don't know of any direct analogue for less in powershell that you can implement easily. Your best bet is to get a windows implementation of less that is outside of cygwin, that way you can just drop in the binary somewhere accessible to your account.
to get grep/vim/wget and other Linux like commands in powershell I suggest running.
iex (new-object net.webclient).downloadstring(‘https://get.scoop.sh’)
then
scoop install grep
scoop install perl
scoop install vim
and to get a list of all of them
scoop search
In Windows 10 PowerShell + Cygwin I use:
gc .\myfile.log | less
Previously I was trying to use cygwin directly:
less .\myfile.log
but it shows binary file because of invalid charset setting between 32b-bit and 64-bit.
I was hoping that Powershell had the equivalent of grep,ls,less, xargs, et
In the case you missed this question (top voted) you might enjoy this answer.