Can a PowerShell script be written to do OCR of the characters displayed on the screen?
Alternatively, can PowerShell assist in doing OCR of an image in the clipboard?
OCR and PowerShell
Creating word files without Office installed
Hello,
I want to generate a word doc from a 2012 server. In my test environment (win 7 + office 2013) the script works perfectly. But on my prod, this line fails:
$word = New-Object -ComObject "Word.application"
The error associated with is:
New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)
I'm thinking maybe it is because Office is not installed on that server? If that's the case, how can we generate a word doc without Office installed ?
Thanks all for your time & help!
Copy folder or file.
New to Windows PowerShell.
I want to automate a tedious procedure.
Is there a line(s) of code that will copy a folder or file from an SD memory card or USB flash drive to an external hard drive?
Thanks in advance for any help.
New-WebServiceProxy -Namespace error
When I use the "namespace" parameter on New-WebServiceProxy, I get the following error:
New-WebServiceProxy : Could not find file 'C:\Users\Administrator\AppData\Local\Temp\2\oydwg_vg.dll'.
At C:\Users\Administrator\Security.ps1:4 char:31
+ $Reports = New-WebServiceProxy <<<< -Uri $URI -UseDefaultCredential -namespace test
+ CategoryInfo : NotSpecified: (:) [New-WebServiceProxy], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.NewWebServiceProxy
When I remove the namespace parameter, it works fine.
The code works on a different machine, a Windows 7 box. The machine where this doesn't work is a Windows Server 2008 R2 Datacenter, Version 6.1.7600 Build 7600, running as a Virtual Machine. The user account under which it runs is "Administrator".
Any thoughts?
Thanks.
Extracting specific data from multiple text files to single CSV
Hello,
Unfortunately my background is not scripting so I am struggling to piece together a powershell script to achieve the below. Hoping an experienced powershell scripter can provide the answer. Thanks in advance.
I have a folder containing approx. 2000 label type files that I need to extract certain information from to index a product catalog. Steps to be performed within the script as I see are:
1. Search folder for *.job file types
2. Search the files for certain criteria and where matched return into single CSV file
3. End result should be a single CSV with column headings:
a) DESCRIPTION
b) MODEL
c) BARCODE
ShowBalloonTip with lastbootuptime, variable difference running from CMD and ISE
I am trying to modify nice script found here to notify a remote user about his computer last boot time in a balloon tip. Script now looks like this:
param ( $msg = "This Computer has not been rebooted in $Date days. Please reboot to apply important system and security updates.", $Date = ((get-date)-([System.Management.ManagementDateTimeconverter]::ToDateTime((Get-WmiObject win32_operatingsystem).lastbootuptime))|select days -ExpandProperty Days), $title = "Reboot PC", $icon = "2", $timeout=1 ) # if number of days of last reboot is greater than 10 days show baloon if ($Date -gt "0") { [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | out-null $Balloon = new-object System.Windows.Forms.NotifyIcon $Balloon.Icon = [System.Drawing.SystemIcons]::Information $Balloon.Visible = $true; $Balloon.ShowBalloonTip($timeout, $title, $msg, $icon); Unregister-Event -SourceIdentifier click_event -ErrorAction SilentlyContinue | Out-Null Wait-Event -timeout 5 -sourceIdentifier click_event > $null Remove-Event click_event -ea SilentlyContinue Unregister-Event -SourceIdentifier click_event -ErrorAction SilentlyContinue $Balloon.Dispose() } # if number of days of last reboot is less than 10 days than exit else { exit }
It works fine when running from Powershell_ISE, you can see variable $Date in a balloon tip showing number of dates since last reboot but when running from command prompt or even powershell prompt variable $Date is omitted and not shown. Does anyone know why this is happening and what I should do to correct a script?
Thanks!
PS. if you are testing script make sure number of days since last reboot corresponds with your system value otherwise you will not see balloon popping up
How can I combine Add-DnsServerResourceRecordA & Add-DnsServerResourceRecordPTR cmdlets to automate creating DNS records?
PowerShell gurus,
We are running Windows Server 2012 R2 with PowerShell v4.0 and want to take advantage of the new Add-DnsServerResourceRecordA and Add-DnsServerResourceRecordPTR cmdlets (and remove-dnsserverresourcerecord) to automate as much as possible the creation/deletion of statically configured DNS records.
Question: how can I combine these two cmdlets to run to create the DNS 'A' and DNS 'PTR' records in one long cmdlet? How would we make it so we can run both of these below together as one cmdlet?
Add-DnsServerResourceRecordA-Name "hostname123"-ZoneName "contoso.com"-AllowUpdateAny -IPv4Address"192.168.0.123" -TimeToLive 01:00:00
Add-DnsServerResourceRecordPtr -Name "123" -ZoneName "0.168.192.in-addr.arpa" -AllowUpdateAny -TimeToLive 01:00:00 -AgeRecord -PtrDomainName"hostname123.contoso.com"
As we develop our competence with powershell, we would like to make it so we can use (get-content) to import DNS entries from a .csv file then as much as possible automate the creation of DNS 'A' and 'PTR' records. How can we do this?
Thank you for your insight and ideas!
Cheers!
Matt
Powershell Script to export Virtual Machines
30 day inactive AD user account & computer report using Powershell
Hello all,
I am a newbie to Powershell and would greatly appreciate it if someone can tell me how to run a report listing all user accounts & computers that's been inactive for the last 30 days.
Find specific item based on itemproperty
Trying to loop through some items in the registry to find the one that contains an itemproperty with a specific value ("VMware Tools"). I was thinking this would work:
Get-Item -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object {(Get-ItemProperty -Path $_ -Name DisplayName) -match "VMware Tools"}
But it just loops through with an error for each item saying
Get-ItemProperty : Cannot find path 'C:\_scripts\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\{ED98ABF5-B6BF-47ED-92AB-1CDCAB964447}' because it does not exist.
At line:1 char:95
+ ... Where-Object {(Get-ItemProperty -Path $_ -Name "DisplayName") -match "VMware Too ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\_scripts\HKE...B-1CDCAB964447}:String) [Get-ItemProperty], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand
The guid changes for each error. What am I missing here?
How to edit the parameter in registry remotely
I Have a task to edit the value in registry using powershell remotely.
Remote server Name: ABCDEF
Service Name: SHELL
Parameter Name: BACKUPPATH
Full Path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SHELL\Parameters\BACKUPPATH
New value: D:\Backup\SHELL|E:\SHELL
Export AD users with orgranizationUnit
Hi
I am using this Poweshell script to export users with last login time. Can any one help with, how I can include organizationUnit in the export file.
$NumDays = 0
$LogDir = ".\Users-Last-Logon.csv"
$currentDate = [System.DateTime]::Now
$currentDateUtc = $currentDate.ToUniversalTime()
$lltstamplimit = $currentDateUtc.AddDays(- $NumDays)
$lltIntLimit = $lltstampLimit.ToFileTime()
$adobjroot = [adsi]''
$objstalesearcher = New-Object System.DirectoryServices.DirectorySearcher($adobjroot)
$objstalesearcher.filter = "(&(objectCategory=person)(objectClass=user)(lastLogonTimeStamp<=" + $lltIntLimit + "))"
$objstalesearcher.PageSize=4000
$users = $objstalesearcher.findall() | select `
@{e={$_.properties.cn};n='Display Name'},`
@{e={$_.properties.cn};f='Organization'},`
@{e={$_.properties.samaccountname};n='Username'},`
@{e={[datetime]::FromFileTimeUtc([int64]$_.properties.lastlogontimestamp[0])};n='Last Logon'},`
@{e={[string]$adspath=$_.properties.adspath;$account=[ADSI]$adspath;$account.psbase.invokeget('AccountDisabled')};n='Account Is Disabled'}
$users | Export-CSV -NoType $LogDir
compare two strings in if-then-else statement
Hi
I put a compare command into an if-then-else statement like this:
IF (Compare-Object$str1$str2)
{
Write-Host"strings are different"
}
ELSE
{
Write-Host"strings are equal"
}
If the strings are equal, the else statement is fired and NOT the first part, why?
update pivot table cell then refresh
I want to update my pivot table that connects to my SQL2008R2 AS. The requirement is to update the ship date with cuurent date then refresh
all Tabs with WorkBook. Here is my code that doesn't allow me to update the cell. The xcel version is 2003.
$year=(Get-Date).Year $month="{0:dd-MMM}" -f (Get-Date) $sdate="{0:yyyy-MM-dd}" -f (Get-Date) # Create base object $xl = new-object -comobject Excel.Application # make Excel visible #$xl.visible = $true $xl.DisplayAlerts = $False # open a workbook $wb = $xl.workbooks.open("C:\archive\ShipmentDetailEur.v4.xls") # Get sheet1 $ws = $wb.worksheets | where {$_.name -eq "CustShipmentDetail"} $sdate=[char]39 + "{0:yyyy-MM-dd}" -f (Get-Date) # '2012-08-30 $ws.Cells.Item(11,2) = $sdate $wb.Save() #logging stuff Write-Host $wb.Name write-host $wb.Path $xl.Quit()
Error:
Exception setting "Item": "You cannot select an item in this field
Thanks.
Import-csv line by line
I need to read a CSV file in and act upon the data line by line.
The code I have (in msdos) reads a CSV file in one line at a time and then depending upon a (text) date value in one field creates a new file and outputs the line to that. So from one CSV file you end up with several CSV files depending upon this date.
import-csv seems to read it all in one one go so should I use something else for this problem?
Cannot bind argument to parameter 'Path' because it is null in ISE
Hi there,
i am facing a "for me" confusing error in ISE...
I just started with PS Scripting and created the following little script:
Param(
[string]$computerName,
[string]$RegKey
)
Invoke-Command -computername $computerName {Remove-Item -path $RegKey -Recurse}
When running this i am getting that Error:
Cannot bind argument to parameter 'Path' because it is null.
+ CategoryInfo : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Co
mmands.RemoveItemCommand
+ PSComputerName : xxxxxxx
Whle Debugging i verified the Parameters, they looked good, if i fire the invoke-command line alone it works fine, so i dont get it whats wrong with that?!?
Any idea hint, help?
best regards
Christof
script optimisation
Hello
I dont have expirience with PowerShell, but since we use Microsoft Windows Server 2012, i have to write some scripts with PowerShell (3.0)
So i did for now a simple script, that should search for strings in config files (about 200 files each run) - but it is very slow.
here a short example (.\config.txt just contains lines like "logging=10.10.10.10)
$config = Get-Content -Path .\config.txt
$files = Get-Childitem $pwd *.rtf -Recurse | Where-Object { !($_.psiscontainer) }
$logging = echo $config | Select-String -pattern "logging="
if (-not ($logging | Select-String "#"))
{
$logging = $logging.ToString().Substring(8)
} else
{
$logging = $null
}Function getStringMatch { # Loop through all *.rtf files in the $pwd directory Foreach ($file In $files) { $hostname = Get-Content $file.FullName | Select-String -pattern "hostname" $hostname = $hostname.ToString().Substring(9) if ($logging -ne $null) { # logging server $result = Get-Content $file.FullName | Select-String -pattern "logging 10" if ($result -eq $null) { echo "no logging server on host $hostname" } else { Foreach ($i In $result) { if ( -not ($i | Select-String -pattern $logging)) { echo "wrong logging server: $i on host $hostname" } } } } } }
getStringMatch
Is there some possobility to make it faster?
and why does the output contains "\par" after strings. Here my for example my testcase output
wrong logging server: logging 10.10.10.10\par on host testhostname\par
Thank you
Get the list of Users added to IIS authorization
I have to add 100 of users to the FTP authorization rules within IIS. I am able to achieve such using Add-WebConfiguration, however I am unable to get the list of users i have added using powershell.
Is there any command to get the list of authorized user for Default FTP site?
powershell ise error
Psexec med Windows Update VBScript
Hi it's Possible to run Psexec with PowerShell ?
psexec \\COMPUTERNAME -u domain\username -p password %SYSTEMROOT%\system32\cscript C:\WUA_SearchDownloadInstall.vbs
I have done a powershell script there is all computers in AD , computers.txt
I want to run all computers in that command..
Grateful for answer--
----- S-O-K-O-B-A-N -----