powershell

VBA Macro to run PowerShell Command

我的梦境 提交于 2021-02-10 18:49:27
问题 I am trying to create a macro, that would be able to rename all files with ".docx" extension in a folder. The PowerShell command works when used directly, but when used through the VBA code, it's not executing. Sub test() Dim retval Dim pscmd pscmd = "PowerShell -ExecutionPolicy Bypass -Command ""Get-ChildItem -Path *.docx -Recurse | Rename-Item -NewName {$_.Name.Substring(0,7) + $_.Extension }""" retval = Shell(pscmd, vbNormalFocus) Debug.Print pscmd End Sub The script is executing without

How substitute variable in PowerShell SQL query

人盡茶涼 提交于 2021-02-10 18:48:47
问题 I need to use a variable in my SQL query. This is my script: function SQLQueryWriteToFile([string]$SQLquery, [string]$extractFile, [string]$facility) { #create sql connection to connect to the sql DB $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnection.ConnectionString = "Server=blah;Database=blah_Test;User ID=blah;Password=blah" $sqlConnection.Open() #Create a SqlCommand object to define the query $sqlCmd = New-Object System.Data.SqlClient.SqlCommand $sqlCmd

Embed powershell script in VBA macro and run it from there

北慕城南 提交于 2021-02-10 18:41:34
问题 I am trying to write this neat little bit of code and am having some massive issues with the last bit of it. So the intention was to write a code that would go into all the .zip files in a folder, find a folder in each by name, go inside, find a file ending in "_nl.inp" and copy it outside the archive. While digging for ideas as far as VBA goes I could only find how to unzip the entire archive and not just pinpoint the file and pull i out. But I managed to find how to do this in powershell

Embed powershell script in VBA macro and run it from there

房东的猫 提交于 2021-02-10 18:40:51
问题 I am trying to write this neat little bit of code and am having some massive issues with the last bit of it. So the intention was to write a code that would go into all the .zip files in a folder, find a folder in each by name, go inside, find a file ending in "_nl.inp" and copy it outside the archive. While digging for ideas as far as VBA goes I could only find how to unzip the entire archive and not just pinpoint the file and pull i out. But I managed to find how to do this in powershell

Pass a Variable group name using REST API Azure devops

ぃ、小莉子 提交于 2021-02-10 18:26:42
问题 Is there any way to pass a variable group name to a release pipeline using REST API without editing the release definition. I am able to do it using the following $defurl = "https://vsrm.dev.azure.com/org/proj/_apis/release/definitions/13?api-version=5.1" $def = Invoke-RestMethod -Uri $defurl -Method Get -Headers $header $def.variableGroups="VariableGroupName" $json = @($def) | ConvertTo-Json -Depth 99 $udef = Invoke-RestMethod -Uri $defurl -Method Put -Body $json -ContentType "application

How to identify the default audio device in Powershell?

流过昼夜 提交于 2021-02-10 18:25:39
问题 I am looking for a solution to get the default audio device via Powershell. In best case, it could work via embedded C#-code to directly use IMMDeviceEnumerator::GetDefaultAudioEndpoint (see here IMMDeviceEnumertor). But if it is easier to get this via RegKeys, then this is also OK. I have seen a couple of code-snippets reading the keys from HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render or \Capture, but I still struggle to identify the DEFAULT device. It seems, when I

powershell remote

非 Y 不嫁゛ 提交于 2021-02-10 18:10:18
问题 I am trying to run this from my local machine (Win7 & PS v2.0) cls $sess = Enter-PSSession -ComputerName blmcrmpoc Invoke-Command -Session $sess -Scriptblock { $path = "C:\inetpub\logs\LogFiles" $lastWrite = (Get-Date).AddDays(-90) $oldLogs = Get-ChildItem -path $path -Recurse -Filter *.log | Where {$_.LastWriteTime -le $lastWrite} if ($oldlogs.count -gt 0) {foreach ($log in $oldLogs) {$log.Delete()}}} But I get this error. ***Invoke-Command : Cannot validate argument on parameter 'Session'.

powershell remote

泪湿孤枕 提交于 2021-02-10 18:06:08
问题 I am trying to run this from my local machine (Win7 & PS v2.0) cls $sess = Enter-PSSession -ComputerName blmcrmpoc Invoke-Command -Session $sess -Scriptblock { $path = "C:\inetpub\logs\LogFiles" $lastWrite = (Get-Date).AddDays(-90) $oldLogs = Get-ChildItem -path $path -Recurse -Filter *.log | Where {$_.LastWriteTime -le $lastWrite} if ($oldlogs.count -gt 0) {foreach ($log in $oldLogs) {$log.Delete()}}} But I get this error. ***Invoke-Command : Cannot validate argument on parameter 'Session'.

New-AzureRmResourceGroup command not working in powershell

女生的网名这么多〃 提交于 2021-02-10 17:47:06
问题 I have logged into my Azure account and selected the appropriate subscription. But it always gives the same error PS C:\WINDOWS\system32> New-AzureRmResourceGroup -Name "AzureMediaServicesSample" -Location "East US" New-AzureRmResourceGroup : Run Login-AzureRmAccount to login. At line:1 char:1 + New-AzureRmResourceGroup -Name "AzureMediaServicesSample" -Location " ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New

New-AzureRmResourceGroup command not working in powershell

試著忘記壹切 提交于 2021-02-10 17:47:02
问题 I have logged into my Azure account and selected the appropriate subscription. But it always gives the same error PS C:\WINDOWS\system32> New-AzureRmResourceGroup -Name "AzureMediaServicesSample" -Location "East US" New-AzureRmResourceGroup : Run Login-AzureRmAccount to login. At line:1 char:1 + New-AzureRmResourceGroup -Name "AzureMediaServicesSample" -Location " ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New