Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Do Until both Ethernet adapters are live

$
0
0
We're replacing some desktop PCs and upon swapping the first one, we've discovered Windows takes a few moments to recognize the second ethernet connection ( one is dynamic, one is static )  I think I've gotten the script correct but I cannot access the one computer because it's now production :/ anyway.  Can someone help me with the script I have so far

do {Start-Sleep -Seconds 1;}until(
Get-WmiObject -Class win32_networkadapter | Where-Object {
    $_.Name -like "*Ethernet*" -and $_.NetEnabled -eq 'True' } | 
    Select-Object Name, Netconnectionstatus
)Start-Process notepad.exe

I essentially want it to wait until BOTH ehternets are stating a live and then start an application

Get-ACL error on AD objects under OU with colon in the name

$
0
0

Hello all,

I am having an issue with the Get-ACL cmdlet where it cannot parse sub-objects underneath a System Container with a colon in the name (e.g.CN=Microsoft,CN=1:1,CN=Pools,CN=RTC Service,CN=Microsoft,CN=System,DC=contoso,DC=com).

However, Get-ACL can parse the container itself (including the colon) just fine.

This is true not just for Containers, but for OU's as well. For example:

#works fine on "colon" object itself
get-acl -Path "AD:OU=System:Stuff,DC=contoso,DC=com"

#FAILS when asking for sub-object under "colon" object
get-acl -Path "AD:CN=TestUser123,OU=System:Stuff,DC=contoso,DC=com"

I have tried -LiteralPath also, and all kinds of combinations of escapes, single quotes, Join-Path, etc. with no luck.

Any thoughts on how to get the second command above to work?

Deploying SSRS Reports using Powershell Method not found

$
0
0

I'm using this template from TechNet to deploy my SSRS reports with powershell...

http://gallery.technet.microsoft.com/Bulk-Report-Deployment-f03e1aac/view/Discussions

This line gives me an unknown method error...

 $Warnings = $SSRSProxy.CreateReport($_.ReportName, $_.TargetReportFolder, $True, $Bytes, $Null) 

So I replaced the method "CreateReport" with "CreateCatalogItem". But when I try to run it with my server information it yields...

"Cannot find an overload for "CreateCatalogItem" and the argument count: "5".
At C:\Users\mike.davis\Desktop\Test\REPORTS\TPF Report\TPF Report\bin\Debug\Bulk SSRS Report Deployment with PowerShell.ps1:26 char:45
+     $Warnings = $SSRSProxy.CreateCatalogItem <<<< ($_.ReportName, $_.TargetReportFolder, $True, $Bytes, $Null)
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest"

What is the correct method to use in this situation when I have ReportingServices2010?


Set-Acl issue

$
0
0

Hi All

First:

What am I running (part of a bigger script):

$strhomedrive="\\blabla\bla"
$strsamid1="id10000"
$HomeDriveAcl2=Get-Acl $strhomedrive
$Ar2 = New-Object System.Security.AccessControl.FileSystemAccessRule($strsamid1, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$HomeDriveAcl2.addAccessRule($Ar2)
Set-Acl $strhomedrive $HomeDriveAcl2

\\blabla\ is DFS path

Works fine with my account: member of Administrator group, not domain admin, member of every local admin group on the servers

it doesn't work with Service Desk account:

Set-Acl : Attempted to perform an unauthorized operation.+ CategoryInfo          : PermissionDenied: (\\blabla\bla:String) [Set-Acl], UnauthorizedAccessException+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetAclCommand


Both my account and SD account have Full control on \\blabla on share level and file level, all effective permissions are green for both

-I tried to run elevated powershell with SD account by adding it to local admins - same error

-tried getting to \\blabla\bla using DFS path and directly to the server (\\server01\bla) - same error

-I can make SD user owner of \\blabla\bla using my domain admin account - same error

PS C:\Windows> ($HomeDriveAcl2).AreAccessRulesProtected
False

PS C:\Windows> ($HomeDriveAcl2).Accessruletype

IsPublic IsSerial Name                                     BaseType                                                                                                                            
-------- -------- ----                                     --------                                                                                                                            
True     False    FileSystemAccessRule                     System.Security.AccessControl.AccessRule 

what I've noticed:

while running this with SD account it takes ownership and adds single user ID (the one who ran the script) with full control in \\blabla\bla folder - it doesn't do that with my personal account

Any idea how to fix it, or maybe workaround with icacls? thanks



Get the latest logs from the log file

$
0
0

Hi Everyone,

I am trying to fetch last 60 mins logs from my log file using powershell. Below is the sample of my log file:

2018-08-15T19:46:24.900 p1-rtap-dp-1054646217-44gcz prta_app: ERROR http-nio2-8180-exec-55 o.g.a.r.e.ReturnHeaderException.<init> - Exception occurred due toYou are not allowed to access Return for selected return period

2018-08-15T19:46:24.901 p1-rtap-dp-1054646217-44gcz prta_app: ERROR http-nio2-8180-exec-55 o.g.a.r.r.r.ReturnsRestController.getGSTR1Summary - ReturnHeaderException 

Please help as I am stuck at this. I need to pull last 60 mins logs from the log file.

Thanks in advance


Rahul Goyal

Bulk shared mailbox rename using powershell

$
0
0

we have few shared mailboxes for one of our clients who has few branches and we have shared mailbox for each branch. 

Eg- branch1@domain.com

      branch2@domain.com

      branch3@domain.com

We need to rename those and I have an excel sheet with the current display name,the name it should be changed to and the email ID.

I need a power shell command to change all this in office 365. Can someone give me the power shell command please?

XML node InsertAfter is not working properly

$
0
0

In VS *.csproj file, I have 3 Itemgroup tags, Inside in 2nd tag I have update one more tag like below 

       <Res Include = "3" >  
            <Culture>fr</Culture>  
        </Res>

Using insertbefore method I can update above tag at ======location 1 ======
using $root.insertafter($a, $root,itemgroup.item(1))

but I want to add the tag at ======location 1 ======and getting error that 
and for that I am changing above code  as $root.insertafter($a, $root,itemgroup.item(1).name)

can not convert itemgroup type string to system.xml.xmlnode

{I just want to add node at location 2 instead of location 1 }

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
   1. <ItemGroup>  <X= "Strings.fr.resources" >  <Culture>fr</Culture>  </X>  <XX= "Dialogs.fr.resources" >  <Culture>fr</Culture>  </XX>  </ItemGroup> 
======location 1 don't want to add node here======
    2.<ItemGroup>  
======location 2 just want to add node here======<Res Include = "1" >  <Culture>fr</Culture>  </Res>  <Res Include = "2" >  <Culture>fr</Culture>  </Res>  </ItemGroup>

   3.<ItemGroup>  <Res YY= "Strings.fr.resources" >  <Culture>fr</Culture>  </YY>  <Res YY = "Dialogs.fr.resources" >  <Culture>fr</Culture>  </YY>  </ItemGroup><projectgroup><projectdetails = "Strings.fr.resources" >  <Culture>fr</Culture>  </projectdetails>  </projectgroup></Project>  



PowerShell doesnt load values from .csv File

$
0
0

Hi,

I want to automatically create Users in Active Directory using a .csv File and Powershell.My .csv GFile Looks like this:

firstnamemiddleInitiallastnameusernameemail  streetaddresscityzipcodestatecountrydepartmentpasswordtelephonejobtitlecompanyou

Test             Test                                 Test           testmailadress

and so on, so on....I filled it up with the values I Need.Now i want to load the values into a Array using Powershell:

$ADUsers=Import-csv  pathtocsv
 #Loop through each row containing user details in the CSV file 

foreach
  
($Userin$ADUsers)

{
  
#Read user data from each field in each row and assign the data to a variable as below

$Username=$User.username
$Password=$User.password
$Firstname=$User.firstname
$Lastname=$User.lastname
$OU=$User.ou #This field refers to the OU the user account is to be created in
$email      =$User.email
$streetaddress=$User.streetaddress
$city       =$User.city
$zipcode    =$User.zipcode
$state      =$User.state
$country    =$User.country
$telephone  =$User.telephone
$jobtitle   =$User.jobtitle
$company    =$User.company
$department=$User.department
$Password=$User.Password
#Check to see if the user already exists in AD
if(Get-ADUser-F{SamAccountName-eq$Username})
{
#If user does exist, give a warning
Write-Warning"A user account with username $Usernamealready exist in Active Directory."
 }
else
{
#User does not exist then proceed to create the new user account
#Account will be created in the OU provided by the $OU variable read from the CSV file
New-ADUser`
-SamAccountName$Username`
-UserPrincipalName$usernameanddomain
-Name"$Firstname$Lastname"`
-GivenName$Firstname`
-Surname$Lastname`
-Enabled$True`
-DisplayName"$Lastname, $Firstname"`
-Path$OU`
-City$city`
-Company$company`
-State$state`
-StreetAddress$streetaddress`
-OfficePhone$telephone`
-EmailAddress$email`
-Title$jobtitle`
-Department$department`
-AccountPassword(convertto-securestring$Password-AsPlainText-Force) -ChangePasswordAtLogon$False
}

} 


as far as i know thats the way to go right?

But as soon as i start the script it tells me that the varibale $Username is not definded.

How come this error happens? the path to the .csv File works properly.

Sorry for bad english I'm not a native Speaker...





DSC for executing a .ps1 file

$
0
0

Hi,

Can someone guide me or share me a sample script or the process to execute a .ps1 file within powershell DSC

convert .eml to .msg

$
0
0

I have 500000 .eml files that needs to be converted to .msg file and save in local folder.

I want to know if we have any powershell command to do so?

Or any other efficient method to achieve this??(C#)

PS: Dont want to use third party converters.

How do I find an Invoke-CimMethod ReturnValue enum

$
0
0

I'm using Invoke-CimMethod on the Win32_services class. How do i find a list/enum of what the .returnvalue means? For example, I see that when use the method StartService on a service that's already started I get a returnvalue of 10. When i try to start a service that's disabled i get a returnvalue of 3.

Is there a way to either output the list from PS or a good internet search query or site that i should be looking at?

 

Tony Auby

Powershell Set-Acl use without changing owner?

$
0
0
I have a folder, and I am trying to grant full permissions to another user, like so:

$Acl = Get-Acl "C:\MyFolder"

$AccessRule = New-Object  system.security.accesscontrol.filesystemaccessrule("bobby","FullControl", "Allow")
$Acl.AddAccessRule($AccessRule)
Set-Acl -AclObject $Acl "C:\MyFolder"

The owner of the folder is "Joe".
The powershell script runs under the "SyncProcess" account.

If Joe is the owner of the folder, the script fails with the error message:
Set-Acl : The security identifier is not allowed to be the owner of this object

If I change the owner of the folder manually to SyncProcess, then the script runs fine without error.

My question is, why does Set-Acl try to change the owner?  I am not trying to change the owner, nor do I want to.  I read the script to mean, get the current Acl, add the full control permission access rule for Bobby, and then update the folder.  I don't think I am doing anything here to change the owner?

if I add $Acl | fl both before and after the AddAccessRule method call, the Owner is the same in both, unchanged.  Whe does Set-Acl think the owner is changing?

Thanks.

Exception from HRESULT: 0x800A138A At line......

$
0
0
I have PS files that are all ok running on Windows 7 with Powershell 4.
I got error "Exception from HRESULT: 0x800A138A At line......" when running on Windows 10
After logging on the website, cannot get any elements on the page:

$ie = New-Object -Com "InternetExplorer.Application"
$ie.Navigate("https://www.company.com")
While ($ie.busy) { Start-Sleep -S 1 }
$ie.visible = $true
$ie.Document.getElementById('logonID').value = 'MyLogonID'
$ie.Document.getElementById('password').value = 'myPassword'
$ie.Document.getElementById('logonButton').click()
While ($ie.busy) { Start-Sleep -S 1 }

$t = $ie.document.getElementsByTagName('table')
Exception from HRESULT: 0x800A01B6
At line:1 char:1
+ $t = $ie.document.getElementsByTagName('table')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], NotSupportedException
    + FullyQualifiedErrorId : System.NotSupportedException



ThumbnailPhoto attribute , I get error A value for the attribute was not in the acceptable range of values

$
0
0

when I create a user using NEW-ADUser , it creates user but it does not create thumbnailphoto attribute

so I used

$PicFile    = FilePath\Filename.jpg

Set-ADuser-identity$Username-Add@{thumbnailPhoto=([byte[]](Get-Content$PicFile-Encodingbyte))}

but now I get error

A value for the attribute was not in the acceptable range of values

What I am doing wrong. Jpog file is a picture...


Burfuri

SOAP request using Powershell

$
0
0

Hi All,

I have a task to try and automate Cisco UCM tasks such as creating EM Profile,Add DN etc using MS Orchestrator & Powershell. When i go through the blogs i could see that Cisco provides AXL toolkit to facilitate these tasks. I tried using the MS ORchestrator webservices but got stuck with a known bug in SCO. So now left with POSH. I tried passing few queries which i saw online but could not get any response.

I have downloaded a AXL Toolkit from CUCM but how can i use the wsdl files for doing the tasks. Any guidance or suggestions would be of much help.

function Get-CUCMUser {
    param(
        [Parameter(Mandatory)][String]$UserID
    )

    $AXL = @"<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 

xmlns:ns="http://www.cisco.com/AXL/API/9.1"><soapenv:Header/><soapenv:Body><ns:getUser><userid>$UserID</userid></ns:getUser></soapenv:Body></soapenv:Envelope>"@
    $XmlContent = Invoke-CUCMSOAPAPIFunction -AXL $AXL -MethodName getUser
    $XmlContent.Envelope.Body.getUserResponse.return.user
}

 

Justin


How to not send file attachment if contents are empty in Powershell

$
0
0

I wrote some powershell code to export a file. What code should I write to NOT export the file if the file contents are empty?

The end of the code is below:

$extractFile = "C:\Users\testname + $(((get-date).ToUniversalTime()).ToString("yyyyMMddThhmmssZ")) + $filename
$testsummary= $QueryBaseResults.Tables[2] | Select 'value1', 'value2', 'value3', 'value4', 'value5' -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors  | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 |Set-Content -Path $extractFile

Thank you.

How to move data fields to specified locations on the export file using Powershell

$
0
0

I wrote some powershell code to export a file. I need data points to be in specific locations on the output file. For example, in the code I wrote below, if I would like 'value2' listed on the 3rd column of the csv export file (C:1 in excel). It currently exports to the second column because it is the second value provided. 

The end of the code is below:

$extractFile = "C:\Users\testname + $(((get-date).ToUniversalTime()).ToString("yyyyMMddThhmmssZ")) + $filename
$testsummary= $QueryBaseResults.Tables[2] | Select 'value1', 'value2', 'value3', 'value4', 'value5' -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors  | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 |Set-Content -Path $extractFile

Thank you.

What structured data is stored in the format label : data

$
0
0

I have some data I've extracted from a .JSON file.  It's in the format label : data.  It's not an array; it's not a hash table.  What is it?

Need help with Powershell API authentication

$
0
0

Hi

I am a newbie to scripting world,learning powershell.I need to automate the loadbalancer(login to loadbalancer,enable/disable nodes and log out).That loadbalancer site has API,JSON content.

How can i authenticate to website and get API token silently?I am planning to hardcode username and password in the script itself.The criteria of the script is that less human intervention,i just need to click the script and the script should do everything.

First i need to login to http://xxxx.com(ORIGIN) and login automatically to the webpage(i dont have to see the page)

once i login to that page-it should redirect me to HOST http://xxxx-api.com from ORIGIN-and make subsequent calls.

Thanks

mbijja

PowerShell xml parsing script change encoding

$
0
0

Hi guys

I have an xml file with Shift-JIS encoding inside, there are Japanese and English characters, and after succesfuly parsing this file I see Japan characters broken. Can anyone help me to understand the cause of this issue?

Thanks in advance!

Best regards


Viewing all 21975 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>