get-wmiobject

Pull NT user ID from powershell

筅森魡賤 提交于 2021-02-02 09:54:27
问题 get-wmiobject -class win32_computersystem -computername c73118 | format-table username Will output something similar to: username -------- GHS_NTDOMAIN\amacor Is it possible to only output the amacor part only? 回答1: first, you don't really want FT for this I don't think. Use Select -Expand instead. So doing that we get back the string GHS_NTDOMAIN\amacor . Once you have that, you can do .Split("\") to split it into an array of strings, and [-1] to specify the last string in the array. So it

Combine `Get-Disk` info and `LogicalDisk` info in PowerShell (but with formatted output)

五迷三道 提交于 2020-08-26 07:40:52
问题 This is a question about an answer for this Combine `Get-Disk` info and `LogicalDisk` info in PowerShell? Here is the answer which I've tried to change to get the output formatted how I want it: https://stackoverflow.com/a/31092004/8262102 It needs to work for multiple drives like the code below only in the desired format. This is the code with all the details on what my attempts are to do so: $info_diskdrive_basic = Get-WmiObject Win32_DiskDrive | ForEach-Object { $disk = $_ $partitions =

Disable 'Bidirectional communication' for a printer?

随声附和 提交于 2020-05-17 06:44:28
问题 How do you disable 'Bidirectional communication' using powershell? I can see EnableBIDI when running: get-WmiObject -class Win32_printer | fl * But when I try this, it says the property was not found? Set-PrinterProperty -PrinterName "Some Printer" -PropertyName "EnableBIDI" -Value $False 回答1: You are mixing properties from two different WMI classes. Set-PrinterProperty manipulates instances of the undocumented MSFT_PrinterProperty class from the root/standardcimv2 namespace, which has

'Provider load failure' during installation process

别来无恙 提交于 2019-12-24 19:18:56
问题 I execute two Powershell scripts during a installation process from a desktop application under Windows 10 IoT Enterprise. %WINDIR%\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy Bypass -File ".\KeyboardFilter.ps1" %WINDIR%\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy Bypass -File ".\ShellLauncher.ps1" But the execution of the Powershell scripts is not successful. I get the following errors: Get-WMIObject : Provider load failure At C:\Program Files

Creating Local User on Remote Windows Server and Add to Administrator Group

喜你入骨 提交于 2019-12-08 07:02:32
问题 I have Created PowerShell script to create User on remote Windows Server and add to Administrator group: $Computer = Read-Host "Computer name:" $UserName = Read-Host "User name:" $Password = Read-Host "Password" -AsSecureString $AdminGroup = [ADSI]"WinNT://$Computer/Administrator,group" $User = [ADSI]"WinNT://$Computer/$UserName,user" $Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, (ConvertTo-SecureString $Password -AsPlainText –Force) $User

Creating Local User on Remote Windows Server and Add to Administrator Group

久未见 提交于 2019-12-08 03:20:29
I have Created PowerShell script to create User on remote Windows Server and add to Administrator group: $Computer = Read-Host "Computer name:" $UserName = Read-Host "User name:" $Password = Read-Host "Password" -AsSecureString $AdminGroup = [ADSI]"WinNT://$Computer/Administrator,group" $User = [ADSI]"WinNT://$Computer/$UserName,user" $Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, (ConvertTo-SecureString $Password -AsPlainText –Force) $User.SetPassword($Cred.GetNetworkCredential().Password) $AdminGroup.Add($User.Path) And It gives me below error

How do I write the value of a single property of a object?

笑着哭i 提交于 2019-11-26 05:30:03
This is how my current script looks like: $cpu = Get-WmiObject win32_processor | select LoadPercentage logwrite $cpu The output of the file is: @{LoadPercentage=4} I want it to be only the number so that I can make calculations. That is a pretty simple fix. Instead of selecting the LoadPercentage when running Get-WmiObject just select the property when calling your function. This will write only the number to your log file. $cpulogpath = "C:\Monitoring\$date.csv" function logwrite { param ([string]$logstring) add-content $cpulogpath -value $logstring } $cpu = Get-WmiObject win32_processor #don

How do I write the value of a single property of a object?

只谈情不闲聊 提交于 2019-11-26 00:44:37
问题 This is how my current script looks like: $cpu = Get-WmiObject win32_processor | select LoadPercentage logwrite $cpu #this fuction writes $cpu into a .txt file The output of the file is: @{LoadPercentage=4} I want it to be only the number so that I can make calculations. 回答1: That is a pretty simple fix. Instead of selecting the LoadPercentage when running Get-WmiObject just select the property when calling your function. This will write only the number to your log file. $cpulogpath = "C: