powershell 相关问题

PowerShell是Windows的命令行和脚本实用程序。仅使用此标记来解决有关编写和执行PowerShell脚本的问题。特定于跨平台版本PowerShell Core(Windows,macOS和Linux)的编程问题应标记为[powershell-core]。应在超级用户或服务器故障上询问有关系统管理的问题。


将MXTSessions File导入MobaxTerm

$csvFilename = 'C:\mobaxterm\mobaXterm.csv' $outfile = 'C:\mobaxterm\MobaXterm_Sessions.mxtsessions' $csv = Import-Csv -Path $csvFilename -Delimiter ',' @' [Bookmarks] SubRep= ImgNum=42 '@ | Out-File -FilePath $outfile $output = foreach ($line in $csv) { "$($line.hostname)= #109#0%$($line.ip)%22%[loginuser]%%-1%-1%%%22%%0%0%0%%%-1%0%0%0%%1080%%0%0%1#MobaFont%10%0%0%0%15%236,236,236%0,0,0%180,180,192%0%-1%0%%xterm%-1%0%0,0,0%54,54,54%255,96,96%255,128,128%96,255,96%128,255,128%255,255,54%255,255,128%96,96,255%128,128,255%255,54,255%255,128,255%54,255,255%128,255,255%236,236,236%255,255,255%80%24%0%1%-1%<none>%%0#0#" } $output | Out-File -FilePath $outfile -Append

回答 2 投票 0

如何将字符串数组作为param从函数传递到get-process/where-object

[string[]]$Procs = "notepad","mspaint" $Procs -replace '","','|' $Processes = Get-Process | where-object {$_.name -match $Procs} | select-object name, ID $Processes2 = Get-Process | where-object {$_.name -match "notepad|mspaint"} | select-object name, ID write-host "-------- Processes --------" $Processes write-host "-------- Processes2 --------" $Processes2 notepad mspaint -------- Processes -------- -------- Processes2 -------- Name Id ---- -- mspaint 28772 mspaint 32336 notepad 2172 notepad 21168 notepad++ 21056

回答 2 投票 0






用powerShell

<GameProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <ProfileName>NAME</ProfileName> <GameNameInternal>GAME NAME HERE</GameNameInternal> <GameGenreInternal>Fighting</GameGenreInternal> <GamePath>PATH GOES HERE</GamePath> <TestMenuParameter/> <TestMenuIsExecutable>false</TestMenuIsExecutable> <ExtraParameters/> <TestMenuExtraParameters/> <IconName>Icons/TITLE.png</IconName> <ResetHint>false</ResetHint> <ConfigValues> ... </ConfigValues> <JoystickButtons> <JoystickButtons> <ButtonName>Test</ButtonName> <XInputButton> ... </XInputButton> <InputMapping>Test</InputMapping> <AnalogType>None</AnalogType> <BindNameXi>Input Device 0 RightThumb</BindNameXi> <HideWithDirectInput>false</HideWithDirectInput> <HideWithXInput>false</HideWithXInput> <HideWithRawInput>false</HideWithRawInput> <HideWithKeyboardForAxis>false</HideWithKeyboardForAxis> <HideWithoutKeyboardForAxis>false</HideWithoutKeyboardForAxis> <HideWithRelativeAxis>false</HideWithRelativeAxis> <HideWithoutRelativeAxis>false</HideWithoutRelativeAxis> <HideWithUseDPadForGUN1Stick>false</HideWithUseDPadForGUN1Stick> <HideWithoutUseDPadForGUN1Stick>false</HideWithoutUseDPadForGUN1Stick> <HideWithUseDPadForGUN2Stick>false</HideWithUseDPadForGUN2Stick> <HideWithoutUseDPadForGUN2Stick>false</HideWithoutUseDPadForGUN2Stick> <HideWithUseAnalogAxisToAimGUN1>false</HideWithUseAnalogAxisToAimGUN1> <HideWithoutUseAnalogAxisToAimGUN1>false</HideWithoutUseAnalogAxisToAimGUN1> <HideWithUseAnalogAxisToAimGUN2>false</HideWithUseAnalogAxisToAimGUN2> <HideWithoutUseAnalogAxisToAimGUN2>false</HideWithoutUseAnalogAxisToAimGUN2> <HideWithoutProMode>false</HideWithoutProMode> <HideWithProMode>false</HideWithProMode> </JoystickButtons> I根据我在上一篇文章中收到的信息制作了此脚本。它抓住了所有游戏XML文件,然后循环在每个文件中,并提示我输入发现的每个按钮。一切都起作用,只有它使我的输入“ $ key”并更改“”(如果有)的值。 $games = Get-ChildItem C:\PATH\UserProfiles -Filter "*.xml" $notMatch = "fly","drive","gun","shooter","Racing", "axis" #ignore these types of games foreach($game in $games){ [xml]$gameInfo = Get-Content $game.fullname if(($gameInfo.GameProfile.GameGenreInternal -notmatch ($notMatch -join '|')) -and ($gameInfo.GameProfile.GameNameInternal)){ $xml = New-Object XML $xml.Load("C:\PATH\$game") $gameName = $xml.GameProfile.GameNameInternal $buttons = $xml.GameProfile.JoystickButtons.JoystickButtons Write-Host -ForegroundColor Yellow $gameName Write-Host -ForegroundColor Yellow "----------------------------------------" foreach($button in $buttons){ $key = Read-Host "Map button" '"'$button.ButtonName'"' $key = $host.ui.rawui.readkey() $button.SetAttribute("InputMapping","$Key") #THIS IS THE PART THAT DOEST WORK } write-host "" } } 您正在尝试更新每个按钮的InputMapping属性,但是您用来设置属性的方法并不是很正确。您应该直接设置InputMapping Element的值。 SetAttribute 元素直接以$games = Get-ChildItem C:\PATH\UserProfiles -Filter "*.xml" $notMatch = "fly","drive","gun","shooter","Racing", "axis" #ignore these types of games foreach($game in $games){ [xml]$gameInfo = Get-Content $game.fullname if(($gameInfo.GameProfile.GameGenreInternal -notmatch ($notMatch -join '|')) -and ($gameInfo.GameProfile.GameNameInternal)){ $xml = New-Object XML $xml.Load("C:\PATH\$game") $gameName = $xml.GameProfile.GameNameInternal $buttons = $xml.GameProfile.JoystickButtons.JoystickButtons Write-Host -ForegroundColor Yellow $gameName Write-Host -ForegroundColor Yellow "----------------------------------------" foreach($button in $buttons){ $key = Read-Host "Map button" '"'$button.ButtonName'"' $button.InputMapping = $key # Update the InputMapping element } $xml.Save("C:\PATH\$game") # Save the updated XML file write-host "" } } 的值直接更新。此外,将更新的XML文件保存回了其原始位置。 我应该相信这一点。

回答 1 投票 0

powershell脚本问题使用com对象打开Excel

我遇到的问题是,如果我已经在Excel中打开了工作簿,它可以按预期工作而没有错误,但是如果工作簿不打开(任何人)失败。

回答 0 投票 0



回答 5 投票 0


集群数组对象按属性和sum

我正在努力从CSV文件中获取一些数据,并且不知道要求解最重要的部分 - 我有一个数百行的数组,这些行中有大约50个ID,一个...

回答 1 投票 0

试图通过add-pnpfile将文件添加到SharePoint库中,但是每当将空白值发送到DateTime列时,都不会发送其他值 我有一个脚本添加文件,然后读取Excel表,然后用该数据填充SharePoint文档库。该命令看起来像 add -pnpfile -path $ path -folder $ librar ...

Add-PnPFile -Path $Path -Folder $LibraryName -Values @{"Name" = $Values[0]; "Classification" = $Values[1]; "DocumentID" = $Values[2]; "EffectiveDate" = $Values[3]; "DatePublished" = $Values[4]; "EndDate" = $Values[5]; "RNumber" = $Values[6]}

回答 1 投票 0

如果还没有添加添加的添加类型的类别,我如何有条件地添加类?

考虑以下PowerShell片段: $ CSHARPTRING = @” 使用系统; 公路密封班 { 公共myclass(){} 公共覆盖字符串tostring(){ 返回“这是我的

回答 6 投票 0




最新问题
© www.soinside.com 2019 - 2025. All rights reserved.