< Back
New-GcsObject
Post
NAME New-GcsObject
SYNOPSIS
Uploads a local file or folder into a Google Cloud Storage bucket.
SYNTAX
New-GcsObject [[-Bucket] <string>] [-ObjectName] <string> [[-Value] <string>] [-ContentType <string>]
[-ContentEncoding <string>] [-ContentLanguage <string>] [-ContentDisposition <string>] [-CacheControl <string>]
[-PredefinedAcl {AuthenticatedRead | BucketOwnerFullControl | BucketOwnerRead | Private__ | ProjectPrivate |
PublicRead}] [-Metadata <Hashtable>] [-Force <SwitchParameter>] [<CommonParameters>]
New-GcsObject [[-Bucket] <string>] [[-ObjectName] <string>] [-File] <string> [-ContentType <string>]
[-ContentEncoding <string>] [-ContentLanguage <string>] [-ContentDisposition <string>] [-CacheControl <string>]
[-PredefinedAcl {AuthenticatedRead | BucketOwnerFullControl | BucketOwnerRead | Private__ | ProjectPrivate |
PublicRead}] [-Metadata <Hashtable>] [-Force <SwitchParameter>] [<CommonParameters>]
New-GcsObject [[-Bucket] <string>] [-Folder] <string> [-ObjectNamePrefix <string>] [-ContentEncoding <string>]
[-ContentLanguage <string>] [-ContentDisposition <string>] [-CacheControl <string>] [-PredefinedAcl
{AuthenticatedRead | BucketOwnerFullControl | BucketOwnerRead | Private__ | ProjectPrivate | PublicRead}]
[-Metadata <Hashtable>] [-Force <SwitchParameter>] [<CommonParameters>]
DESCRIPTION
Uploads a local file or folder into a Google Cloud Storage bucket. You can set the value of the new object
directly with -Value, read it from a file with -File, or define neither to create an empty object. You can also
upload an entire folder by giving the folder path to -Folder. However, you will not be able to use -ObjectName or
-ContentType parameter in this case. Use this instead of Write-GcsObject when creating a new Google Cloud Storage
object. You will get a warning if the object already exists.
If this cmdlet is used when PowerShell is in a Google Cloud Storage Provider location (i.e, the shell's location
starts with gs:\\), then you may not need to supply -Bucket. For example, if the location is gs:\\my-bucket, the
cmdlet will automatically fill out -Bucket with "my-bucket". If -Bucket is still used, however, whatever value
given will override "my-bucket". If the location is inside a folder on Google Cloud Storage, then the cmdlet will
prefix the folder name to the object name. For example, if the location is gs:\\my-bucket\\folder-1\\folder-2, the
cmdlet will prefix "folder-1/folder-2/" to the object name. If -ObjectNamePrefix is used, the automatically
determined folder prefix will be appended to the front of the value of -ObjectNamePrefix.
Note: Most Google Cloud Storage utilities, including the PowerShell Provider and the Google Cloud Console treat
'/' as a path separator. They do not, however, treat '\\' the same. If you wish to create an empty object to treat
as a folder, the name should end with '/'.
PARAMETERS
-Bucket <string>
The name of the bucket to upload to. Will also accept a Bucket object.
Required? false
Position? 0
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ObjectName <string>
The name of the created Cloud Storage object.
If uploading a file, will default to the name of the file if not set.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Value <string>
Text content to write to the Storage object. Ignored if File or Folder is specified.
Required? false
Position? 2
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-File <string>
Local path to the file to upload.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Folder <string>
Local path to the folder to upload.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ObjectNamePrefix <string>
When uploading the contents of a directory into Google Cloud Storage, this is the prefix applied to every
object which is uploaded.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ContentType <string>
Content type of the Cloud Storage object. e.g. "image/png" or "text/plain".
For file uploads, the type will be inferred based on the file extension, defaulting to
"application/octet-stream" if no match is found. When passing object content via the -Value parameter, the
type will default to "text/plain; charset=utf-8".
If this parameter is specified, will take precedence over any "Content-Type" value specifed by the -Metadata
parameter.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ContentEncoding <string>
Content encoding of the Cloud Storage object. e.g. "gzip".
This metadata can be used to indcate that an object is compressed, while still maitaining the object's
underlying Content-Type. For example, a text file that is gazip compressed can have the fact that it's a text
file indicated in ContentType and the fact that it's gzip compressed indicated in ContentEncoding.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ContentLanguage <string>
Content language of the Cloud Storage object. e.g. "en".
This metadata indicates the language(s) that the object is intended for. Refer to
https://www.loc.gov/standards/iso639-2/ ... e_list.php for the supported values of this metadata.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ContentDisposition <string>
Specifies presentation information about the data being transmitted.
This metadata allows you to control presentation style of the content, for example determining whether an
attachment should be automatically displayed or whether some form of actions from the user should be required
to open it. See https://tools.ietf.org/html/rfc6266.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-CacheControl <string>
This metadata specifies two different aspects of how data is served from Cloud Storage: whether data can be
cached and whether data can be transformed.
Sets the value to "no-cache" if you do not want the object to be cached. Sets the value to
"max-age=[TIME_IN_SECONDS]" so the object can be cached up to the specified length of time. See
https://cloud.google.com/storage/docs/m ... he-control for more information.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-PredefinedAcl <PredefinedAclEnum>
Set the object's ACL using PredefinedAcl. "Private__" gives the object owner "OWNER" permission. All other
permissions are removed. "ProjectPrivate" gives permission to the project team based on their roles. Anyone
who is part of the team has "READER" permission. Project owners and project editors have "OWNER" permission.
All other permissions are removed. "AuthenticatedRead" gives the object owner "OWNER" permission and gives all
authenticated Google account holders "READER" permission. All other permissions are removed. "PublicRead"
gives the object owner "OWNER" permission and gives all users "READER" permission. All other permissions are
removed. "BucketOwnerRead" gives the object owner "OWNER" permission and the bucket owner "READER" permission.
All other permissions are removed. "BucketOwnerFullControl" gives the object and bucket owners "OWNER"
permission. All other permissions are removed.
To set fine-grained (e.g. individual users or domains) ACLs using PowerShell, use Add-GcsObjectAcl cmdlets.
Possible values: AuthenticatedRead, BucketOwnerFullControl, BucketOwnerRead, Private__, ProjectPrivate,
PublicRead
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Metadata <Hashtable>
Provide metadata for the Cloud Storage object(s). Note that some values, such as "Content-Type",
"Content-MD5", "ETag" have a special meaning to Cloud Storage.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Force <SwitchParameter>
Force the operation to succeed, overwriting existing Storage objects if needed.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.String
Text content to write to the Storage object. Ignored if File or Folder is specified.
OUTPUTS
Google.Apis.Storage.v1.Data.Object
---------- EXAMPLE 1 ----------
PS C:\\> New-GcsObject -Bucket "widget-co-logs" -File "C:\\logs\\log-000.txt"
Upload a local file to GCS. The -ObjectName parameter will default to the file name, "log-000.txt".
---------- EXAMPLE 2 ----------
PS C:\\> "Hello, World!" | New-GcsObject -Bucket "widget-co-logs" -ObjectName "log-000.txt" `
-Metadata @{ "logsource" = $env:computername }
Pipe a string to a file on GCS. Sets a custom metadata value.
---------- EXAMPLE 3 ----------
PS C:\\> cd gs:\\my-bucket\\my-folder
PS gs:\\my-bucket\\my-folder> "Hello, World!" | New-GcsObject -ObjectName "log-000.txt"
Pipe a string to a file on GCS while using the GCS Provider. Here, the object created will be
"my-folder/log-000.txt".
---------- EXAMPLE 4 ----------
PS C:\\> New-GcsObject -Bucket "widget-co-logs" -Folder "$env:SystemDrive\\inetpub\\logs\\LogFiles"
Upload a folder and its contents to GCS. The names of the created objects will be relative to the folder.
RELATED LINKS
SYNOPSIS
Uploads a local file or folder into a Google Cloud Storage bucket.
SYNTAX
New-GcsObject [[-Bucket] <string>] [-ObjectName] <string> [[-Value] <string>] [-ContentType <string>]
[-ContentEncoding <string>] [-ContentLanguage <string>] [-ContentDisposition <string>] [-CacheControl <string>]
[-PredefinedAcl {AuthenticatedRead | BucketOwnerFullControl | BucketOwnerRead | Private__ | ProjectPrivate |
PublicRead}] [-Metadata <Hashtable>] [-Force <SwitchParameter>] [<CommonParameters>]
New-GcsObject [[-Bucket] <string>] [[-ObjectName] <string>] [-File] <string> [-ContentType <string>]
[-ContentEncoding <string>] [-ContentLanguage <string>] [-ContentDisposition <string>] [-CacheControl <string>]
[-PredefinedAcl {AuthenticatedRead | BucketOwnerFullControl | BucketOwnerRead | Private__ | ProjectPrivate |
PublicRead}] [-Metadata <Hashtable>] [-Force <SwitchParameter>] [<CommonParameters>]
New-GcsObject [[-Bucket] <string>] [-Folder] <string> [-ObjectNamePrefix <string>] [-ContentEncoding <string>]
[-ContentLanguage <string>] [-ContentDisposition <string>] [-CacheControl <string>] [-PredefinedAcl
{AuthenticatedRead | BucketOwnerFullControl | BucketOwnerRead | Private__ | ProjectPrivate | PublicRead}]
[-Metadata <Hashtable>] [-Force <SwitchParameter>] [<CommonParameters>]
DESCRIPTION
Uploads a local file or folder into a Google Cloud Storage bucket. You can set the value of the new object
directly with -Value, read it from a file with -File, or define neither to create an empty object. You can also
upload an entire folder by giving the folder path to -Folder. However, you will not be able to use -ObjectName or
-ContentType parameter in this case. Use this instead of Write-GcsObject when creating a new Google Cloud Storage
object. You will get a warning if the object already exists.
If this cmdlet is used when PowerShell is in a Google Cloud Storage Provider location (i.e, the shell's location
starts with gs:\\), then you may not need to supply -Bucket. For example, if the location is gs:\\my-bucket, the
cmdlet will automatically fill out -Bucket with "my-bucket". If -Bucket is still used, however, whatever value
given will override "my-bucket". If the location is inside a folder on Google Cloud Storage, then the cmdlet will
prefix the folder name to the object name. For example, if the location is gs:\\my-bucket\\folder-1\\folder-2, the
cmdlet will prefix "folder-1/folder-2/" to the object name. If -ObjectNamePrefix is used, the automatically
determined folder prefix will be appended to the front of the value of -ObjectNamePrefix.
Note: Most Google Cloud Storage utilities, including the PowerShell Provider and the Google Cloud Console treat
'/' as a path separator. They do not, however, treat '\\' the same. If you wish to create an empty object to treat
as a folder, the name should end with '/'.
PARAMETERS
-Bucket <string>
The name of the bucket to upload to. Will also accept a Bucket object.
Required? false
Position? 0
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ObjectName <string>
The name of the created Cloud Storage object.
If uploading a file, will default to the name of the file if not set.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Value <string>
Text content to write to the Storage object. Ignored if File or Folder is specified.
Required? false
Position? 2
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-File <string>
Local path to the file to upload.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Folder <string>
Local path to the folder to upload.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ObjectNamePrefix <string>
When uploading the contents of a directory into Google Cloud Storage, this is the prefix applied to every
object which is uploaded.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ContentType <string>
Content type of the Cloud Storage object. e.g. "image/png" or "text/plain".
For file uploads, the type will be inferred based on the file extension, defaulting to
"application/octet-stream" if no match is found. When passing object content via the -Value parameter, the
type will default to "text/plain; charset=utf-8".
If this parameter is specified, will take precedence over any "Content-Type" value specifed by the -Metadata
parameter.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ContentEncoding <string>
Content encoding of the Cloud Storage object. e.g. "gzip".
This metadata can be used to indcate that an object is compressed, while still maitaining the object's
underlying Content-Type. For example, a text file that is gazip compressed can have the fact that it's a text
file indicated in ContentType and the fact that it's gzip compressed indicated in ContentEncoding.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ContentLanguage <string>
Content language of the Cloud Storage object. e.g. "en".
This metadata indicates the language(s) that the object is intended for. Refer to
https://www.loc.gov/standards/iso639-2/ ... e_list.php for the supported values of this metadata.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ContentDisposition <string>
Specifies presentation information about the data being transmitted.
This metadata allows you to control presentation style of the content, for example determining whether an
attachment should be automatically displayed or whether some form of actions from the user should be required
to open it. See https://tools.ietf.org/html/rfc6266.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-CacheControl <string>
This metadata specifies two different aspects of how data is served from Cloud Storage: whether data can be
cached and whether data can be transformed.
Sets the value to "no-cache" if you do not want the object to be cached. Sets the value to
"max-age=[TIME_IN_SECONDS]" so the object can be cached up to the specified length of time. See
https://cloud.google.com/storage/docs/m ... he-control for more information.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-PredefinedAcl <PredefinedAclEnum>
Set the object's ACL using PredefinedAcl. "Private__" gives the object owner "OWNER" permission. All other
permissions are removed. "ProjectPrivate" gives permission to the project team based on their roles. Anyone
who is part of the team has "READER" permission. Project owners and project editors have "OWNER" permission.
All other permissions are removed. "AuthenticatedRead" gives the object owner "OWNER" permission and gives all
authenticated Google account holders "READER" permission. All other permissions are removed. "PublicRead"
gives the object owner "OWNER" permission and gives all users "READER" permission. All other permissions are
removed. "BucketOwnerRead" gives the object owner "OWNER" permission and the bucket owner "READER" permission.
All other permissions are removed. "BucketOwnerFullControl" gives the object and bucket owners "OWNER"
permission. All other permissions are removed.
To set fine-grained (e.g. individual users or domains) ACLs using PowerShell, use Add-GcsObjectAcl cmdlets.
Possible values: AuthenticatedRead, BucketOwnerFullControl, BucketOwnerRead, Private__, ProjectPrivate,
PublicRead
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Metadata <Hashtable>
Provide metadata for the Cloud Storage object(s). Note that some values, such as "Content-Type",
"Content-MD5", "ETag" have a special meaning to Cloud Storage.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Force <SwitchParameter>
Force the operation to succeed, overwriting existing Storage objects if needed.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.String
Text content to write to the Storage object. Ignored if File or Folder is specified.
OUTPUTS
Google.Apis.Storage.v1.Data.Object
---------- EXAMPLE 1 ----------
PS C:\\> New-GcsObject -Bucket "widget-co-logs" -File "C:\\logs\\log-000.txt"
Upload a local file to GCS. The -ObjectName parameter will default to the file name, "log-000.txt".
---------- EXAMPLE 2 ----------
PS C:\\> "Hello, World!" | New-GcsObject -Bucket "widget-co-logs" -ObjectName "log-000.txt" `
-Metadata @{ "logsource" = $env:computername }
Pipe a string to a file on GCS. Sets a custom metadata value.
---------- EXAMPLE 3 ----------
PS C:\\> cd gs:\\my-bucket\\my-folder
PS gs:\\my-bucket\\my-folder> "Hello, World!" | New-GcsObject -ObjectName "log-000.txt"
Pipe a string to a file on GCS while using the GCS Provider. Here, the object created will be
"my-folder/log-000.txt".
---------- EXAMPLE 4 ----------
PS C:\\> New-GcsObject -Bucket "widget-co-logs" -Folder "$env:SystemDrive\\inetpub\\logs\\LogFiles"
Upload a folder and its contents to GCS. The names of the created objects will be relative to the folder.
RELATED LINKS