powershell-5.0

PowerShell5 index[0] to the first instance of the string, index[1] to the second instance and so on till finished on a 6800 line windows10 batch file

喜你入骨 提交于 2019-12-12 01:10:03
问题 Powershell5 script choking on special characters in a Windows 10 batch file or is my code fundamentally wrong? Parse 6800 line Windows 10 batch file, find string {LINE2 1-9999} and replace {1-9999} with the line number the code is on, re-write the batch file. There are 54 instances of {LINE2 1-9999}. If I parse the entire batch the first 54 lines are outputed, none of which contains the string. $lines = sls "LINE2" $env:windir\_61.bat | Select-Object -ExpandProperty LineNumber gc $env:windir\

Powershell Remove-Item Cmdlet error

岁酱吖の 提交于 2019-12-11 18:12:10
问题 I'm using powershell to remove a directory with the command: Remove-Item $pathAsString -Recurse -Force However, it gives me the following error: Remove-Item : Cannot remove the item at 'C:\Path' because it is in use. At line:1 char:1 + Remove-Item "C:\Path" -Recurse + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Remove-Item], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell

DSC Configuration Keeps Restarting

眉间皱痕 提交于 2019-12-11 11:27:02
问题 I have my LocalConfigurationManager set up as follows: [DSCLocalConfigurationManager()] Configuration LCMConfig { Node localhost { Settings { RebootNodeIfNeeded = $true ActionAfterReboot = 'ContinueConfiguration' AllowModuleOverwrite = $true DebugMode = 'All' } } } LCMConfig Set-DscLocalConfigurationManager -Path .\LCMConfig -Verbose -Force Then I kick off a DSC Configuration via Start-DscConfiguration -Path .\RDS -Verbose -Wait This configuration sets up an RemoteApp server which involves a

PowerShell 5.0 Class Method Returns “Not all code path returns value within method”

只谈情不闲聊 提交于 2019-12-11 08:37:01
问题 As an experiment with PowerShell 5.0 classes I tried to translate JavaScript code for the Stable Marriage problem at Rosetta Code. It seemed very straight forward, but The second method (Rank) returns the error: Not all code path returns value within method. class Person { # --------------------------------------------------------------- Properties hidden [int]$CandidateIndex = 0 [string]$Name [person]$Fiance = $null [person[]]$Candidates = @() # ----------------------------------------------

Splatting a function with an object's property

牧云@^-^@ 提交于 2019-12-11 07:59:09
问题 In PowerShell you can pass multiple parameters to a function or cmdlet by wrapping them in a hashtable variable, then passing that variable prefixed with @ instead of $ . Is it possible to splat with a hashtable which is a property of another object (i.e. as a one liner)? e.g. below I first have to assign the property ( testInt , testString ) to another variable before I can splat it to Demo . I'd like some way to avoid this additional step, but haven't been able to find a neat solution...

Set Messaging Unit of premium Service Bus to 4 using PowerShell v5

非 Y 不嫁゛ 提交于 2019-12-11 06:02:27
问题 I want to set the messaging unit of premium service bus to 4 via PowerShell 5. Using following command: New-AzureRmServiceBusNamespace -ResourceGroup Default-ServiceBus-NorthEurope ` -Location NorthEurope -NamespaceName #{PremiumServiceBus} -SkuName "Premium" ` -Capacity 4 It gives capacity is unrecognized variable. What to do? 回答1: Capacity parameter is not defined by the Powershlell cmdlet (see documentation). This is possible using REST API. Looks like a disconnect between the PS library

Powershell New-ScheduledTaskSettingsSet

泄露秘密 提交于 2019-12-10 18:24:11
问题 I try to add New-ScheduledTaskSettingsSet with custom settings. As per Technet, there is possible options for MultipleInstances and including StopExisting value. But actual powershell allows me choose only Parallel , Queue or IgnoreNew . Why I can't use StopExisting ? 回答1: If you take a look how the MultipleInstances property is defined, you'll see that it's type is not actually TaskMultipleInstancePolicy, but a generated type named MultipleInstancesEnum : PS C:\>(New-ScheduledTaskSettingsSet

PowerShell v5 - How to install modules to a computer having no internet connection?

不羁岁月 提交于 2019-12-09 16:51:12
问题 I've a machine (v3, internet, no admin access) which I used to download WMF 5.0 and set up another machine(v5, no internet, admin access). Now, I want to use some modules from PowerShellGet on the machine running v5 but no internet connection. I need an option to download *.psm1 file which I can then copy over and use. Just like we have options to download from GitHub. Anyone with a similar issue and any workarounds ? 回答1: Install the Package Management Module on your PowerShell 3 machine,

PowerShell 5.1 - How to uninstall module which is currently use

久未见 提交于 2019-12-08 14:44:55
问题 We are using some PowerShell modules in one deployment PowerShell script. Using following command we are installing module (i.e. XXXX) into "C:\Program Files\WindowsPowerShell\Modules". Install-Module -Name "XXXX" -AllowClobber -RequiredVersion "XXXX" -Repository "XXXX" -Scope AllUsers Now once we used the functionality of this module, we uninstall it at the end of deployment script using following command. Remove-Module -Name "XXXX" -force Uninstall-Module -Name "XXXX" -AllVersions -force

Programmatically Setting Public Property in Class Ctor

做~自己de王妃 提交于 2019-12-08 07:11:02
问题 I want to programmatically set a public property within a class' constructor in PowerShell V5.0. The test class has many public properties that are to be filled in depending on the object passed to the class' constructor (lovingly referred to as '$something') I thought it'd save a lot of code if I created an array of public property names which was accessible and iterate through them, as the setting the value of the public properties is just calling the same method on the $something object