powershell

How do I use WMI to get the current OU of a computer and list all other computers in that OU?

ぐ巨炮叔叔 提交于 2021-02-07 19:47:16
问题 I'm using WMI and am trying to find a powershell script that will allow me get the OU of the local computer and then get a full list of computers in that OU. 回答1: Here you go: $ComputerName = '<Name of Computer>'; $Computer = Get-WmiObject -Namespace 'root\directory\ldap' -Query "Select DS_distinguishedName from DS_computer where DS_cn = '$ComputerName'"; $OU = $Computer.DS_distinguishedName.Substring($Computer.DS_distinguishedName.IndexOf('OU=')); $ComputersInOU = Get-WmiObject -Namespace

Need to make a PowerShell script faster

为君一笑 提交于 2021-02-07 19:31:09
问题 I taught my self Powershell so I do not know everything about it. I need to search a database with the exact amount of lines I have put in (the database is predefined), it contains > 11800 entries. Can you please help me find what is making this slow? Code: $Dict = Get-Content "C:\Users\----\Desktop\Powershell Program\US.txt" if($Right -ne "") { $Comb = $Letter + $Right $total = [int]0 $F = "" do { $F = $Dict | Select-Object -Index $total if($F.Length -eq $Num) { if($F.Chars("0") + $F.Chars(

Replacing characters with diacritics in a string

别来无恙 提交于 2021-02-07 19:20:51
问题 Im trying to get rid of some special characters. In this case Swedish ÅÄÖ and åäö. Why is this not working? The result should be AAOaao but I get ÅÄÖåäO ? $stringX = "ÅÄÖåäö" $stringX = ($stringX -replace "Å$","A") $stringX = ($stringX -replace "Ä$","A") $stringX = ($stringX -replace "Ö$","O") $stringX = ($stringX -replace "å$","a") $stringX = ($stringX -replace "ä$","a") $stringX = ($stringX -replace "ö$","o") "Result = $stringX" 回答1: Oh! You were so close! Removing the $ sign in the "Å$"

Passing argument from C# to called PowerShell Script

有些话、适合烂在心里 提交于 2021-02-07 19:00:17
问题 I have the following function in my C# file: private void RunScriptFile(string scriptPath, string computerName, PSCredential credential) { RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); runspace.Open(); RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace); Pipeline pipeline = runspace.CreatePipeline(); string scriptCommand = "Invoke-Command -ComputerName " + computerName + "

PowerShell quotes for Start-Process ArgumentList

纵饮孤独 提交于 2021-02-07 18:43:29
问题 I'm trying to have the app tablacus explorer open a folder path. This works fine with the following formatting: $ex = 'S:\Tools\explorer\TE64.exe' Start-Process $ex -ArgumentList '"Tabs,Close other tabs" "Open,C:\Program Files"' But I would really like to have the path in a variable ( $dir = 'C:\Program Files' ), and I can't seem to get the quotes right so it gets interpreted properly. Thank you for your help. 回答1: I found two solutions for this on the MS Blog: $Args = @" "Tabs,Close other

PowerShell quotes for Start-Process ArgumentList

北城余情 提交于 2021-02-07 18:40:16
问题 I'm trying to have the app tablacus explorer open a folder path. This works fine with the following formatting: $ex = 'S:\Tools\explorer\TE64.exe' Start-Process $ex -ArgumentList '"Tabs,Close other tabs" "Open,C:\Program Files"' But I would really like to have the path in a variable ( $dir = 'C:\Program Files' ), and I can't seem to get the quotes right so it gets interpreted properly. Thank you for your help. 回答1: I found two solutions for this on the MS Blog: $Args = @" "Tabs,Close other

Access remote Oracle database with Powershell

折月煮酒 提交于 2021-02-07 18:27:30
问题 I need to be able to connect to an Windows 7 based Oracle server (32 bit, Oracle XE) which is on my network. The machine I need to connect from is running Windows 7 64 bit, with Powershell installed on both machines. I have installed the Oracle 32 bit client on my 64 bit machine and have SQL Developer installed on both machines. I want to create a script that connects the the Oracle database and runs a simple SELECT query. I can't get it to connect though. I have tried using ODAC (I think I

What is the difference between New-Object -ComObject in Powershell and CreateObject() in VB?

偶尔善良 提交于 2021-02-07 18:14:29
问题 I have a question about how Windows PowerShell works when dealing with Com Interop. I have a 3rd party application (let's call it ThirdPartyApp ) that exposes an API that I can call into. I can early-bind it in e.g. Excel or Visual Studio and talk to it 'directly'. I can late-bind it in VBScript and still talk to it 'directly'. By 'directly' I mean the way I can call properties and methods exposed by the API using syntax like ThirdPartyApp.Name So in VBScript I can do: Dim api : Set api =

How to open multiple power shell automatically in power shell?

China☆狼群 提交于 2021-02-07 18:14:07
问题 I have my_project.ps1 file from which I am activating virtual environment & starting my project. currently I need to open my powershell then after I need to go to directory where I have saved my .ps1 file & have to open it from powershell only. Is there any way so that I can double click on .ps1 file & it will open automatically in power shell ? 回答1: By design, double-clicking (opening) *.ps1 files from the Windows shell (Desktop, File Explorer, taskbar, Start Menu) does not execute them -

What is the difference between New-Object -ComObject in Powershell and CreateObject() in VB?

大城市里の小女人 提交于 2021-02-07 18:07:34
问题 I have a question about how Windows PowerShell works when dealing with Com Interop. I have a 3rd party application (let's call it ThirdPartyApp ) that exposes an API that I can call into. I can early-bind it in e.g. Excel or Visual Studio and talk to it 'directly'. I can late-bind it in VBScript and still talk to it 'directly'. By 'directly' I mean the way I can call properties and methods exposed by the API using syntax like ThirdPartyApp.Name So in VBScript I can do: Dim api : Set api =