powershell

Replacing any content inbetween second and third underscore

不羁岁月 提交于 2021-01-27 20:55:48
问题 I have a PowerShell Scriptline that replaces(deletes) characters between the second and third underscore with an "_": get-childitem *.pdf | rename-item -newname { $_.name -replace '_\p{L}+, \p{L}+_', "_"} Examples: 12345_00001_LastName, FirstName_09_2018_Text_MoreText.pdf 12345_00002_LastName, FirstName-SecondName_09_2018_Text_MoreText.pdf 12345_00003_LastName, FirstName SecondName_09_2018_Text_MoreText.pdf This _\p{L}+, \p{L}+_ regex only works for the first example. To replace everything

Unable to retrieve stderror and stdout when calling a Powershell script from SSIS

旧街凉风 提交于 2021-01-27 20:31:54
问题 I have an SSIS package that calls some powershell scripts to consume web services. The problem is that when I write to stderror or stdout, the StandardErrorVariable and StandardOutputVariable are not picking up anything that is written to them from the script. The scripts execute just fine, so it isn't a problem with calling the script it just seems as if the standard output streams are not coming back to SSIS. Here's how the Execute Process task is set up: I've tried various ways of writing

How to convert PSCustomObject with additional props to a custom class

旧城冷巷雨未停 提交于 2021-01-27 20:10:12
问题 Is there a neat way to convert a PSCustomObject to a custom class as a function parameter in PowerShell 5.1? The custom object contains additional properties. I'd like to be able to do something like this: class MyClass { [ValidateNotNullOrEmpty()][string]$PropA } $input = [pscustomobject]@{ PropA = 'propA'; AdditionalProp = 'additionalProp'; } function DuckTypingFtw { [CmdletBinding()] param( [Parameter(Mandatory = $True, Position = 0, ValueFromPipeline)] [MyClass] $myObj ) 'Success!' }

How to setup a Powershell Script in Windows Task Scheduler with admin permissions?

前提是你 提交于 2021-01-27 19:50:56
问题 I am running the following PowerShell script that creates a Tableau backup and uploads it to Google Cloud Storage using the Windows Task Scheduler. #Tableau Server backup &$tsm maintenance backup -f $Backups_file -d -u $User -p $Password CD "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin" $backups_folder = "D:\Tableau Server\data\tabsvc\files\backups\" #default backup path for Tableau installation #&$tsm configuration get -k basefilepath.backuprestore $filename = get-childitem

Encapsulate the output of invoke command in a variable - PowerShell

社会主义新天地 提交于 2021-01-27 19:23:43
问题 I have a script that installs Remote Desktop Services on remote machines (from the DC). I'm now at the phase where I check if RDS installed on the connection broker (server) and connection host (server). I want to use invoke-command since a remote powershell session seemed too complicated. This is the code I have: $res = Invoke-Command -ComputerName "testpc.eil.local" -ScriptBlock { if((Get-WindowsFeature -Name "Remote-Desktop-Services").Installed -eq 1) { #i need this output (true or false

How to setup a Powershell Script in Windows Task Scheduler with admin permissions?

青春壹個敷衍的年華 提交于 2021-01-27 19:17:58
问题 I am running the following PowerShell script that creates a Tableau backup and uploads it to Google Cloud Storage using the Windows Task Scheduler. #Tableau Server backup &$tsm maintenance backup -f $Backups_file -d -u $User -p $Password CD "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin" $backups_folder = "D:\Tableau Server\data\tabsvc\files\backups\" #default backup path for Tableau installation #&$tsm configuration get -k basefilepath.backuprestore $filename = get-childitem

How to rename a blob file using powershell

故事扮演 提交于 2021-01-27 19:13:35
问题 seemingly simple task. I just want to rename a blob file, I know I have to copy it to rename or something, then delete the original but this is proving tricky. I have created the storage context (New-AzureStorageContext), and got the blob (Get-AzureStorageBlob), and found Start-AzureStorageBlobCopy, but how to I actually rename it? I'd like to do this within the same container if possible as well. Ideally I'd run it in an Azure Runbook and call it using a webhook I Azure Data Factory v2. I

Powershell/PowerCLI Loop, timeouts and exits

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-27 19:01:29
问题 Here is the scenario - I'm remotely starting a VM via Powershell/PowerCLI (VMwares Powershell module) and once the VM is started I will be running a series of cmdlets against the VM. Currently I have this bit of code: Start-VM "my VM Name" -runAsync $vm = Get-VM | where { $_.name -eq "my VM Name" } start-sleep -seconds 20 do { start-sleep -seconds 5 $toolsStatus = ($VM | Get-View).Guest.ToolsStatus } until ($toolsStatus -eq 'toolsOK') Which works - the VM starts and the loop will check until

A few conundrums with replacing quotes and special characters in CSV files

删除回忆录丶 提交于 2021-01-27 18:24:43
问题 I am having a bit of a conundrum working with some CSV files that need to be cleansed and loaded into a database. I am fairly adept with PowerShell, but poor with regular expressions, and csv column manipulation. Here is the issue I am having; there is a 'notes' field in the CSV file I am working with, that can have all sorts of various characters. The main problem is that I need to remove the line feeds, and quotes WITHIN the field, but leave the regular line feeds and text qualifying quotes

How to import modules into Azure Automation Account using PowerShell?

爱⌒轻易说出口 提交于 2021-01-27 17:55:35
问题 I am trying to figure out how to install modules into an Azure automation Account from the PowerShell gallery, and I am struggling… New-AzAutomationModule should have been able to do this, but it constantly gives a status of “Failed” in the list of modules in Azure Automation. The command I used is this: $AzMods = Find-Module az.* ForEach ($AzMod in $AZMods) { New-AzAutomationModule -AutomationAccountName $AAccName -Name $AzMod.Name -ContentLinkUri "$($AZMod.RepositorySourceLocation)package/$